1

I have a url:

http://www.abc.com?refurl=/english/info/test.aspx?form=1&h=test&s=AB

If I use

Request.QueryString["refurl"

but gives me

/english/info/test.aspx?form=1

instead I need full url

/english/info/test.aspx?form=1&h=test&s=AB
1
  • But first of all, your query string contains two ? that is not in the correct format - and because you make this, is better to fix that. You can fix by using the UrlEncode function, when you add a full url string Commented Feb 11, 2013 at 7:43

4 Answers 4

3

Fix the problem, and the problem is that you place a full url as parameter refurl with out encoding it.

So where you create that url string use the UrlEncode() function, eg:

"http://www.abc.com?refurl=" + Server.UrlEncode(ReturnUrlParam)

where
ReturnUrlParam="/english/info/test.aspx?form=1&h=test&s=AB";

Sign up to request clarification or add additional context in comments.

Comments

1

For that particular case you shouldn't use QueryString, (since your query string contains three parameters,) instead use Uri class, and Uri.Query will give you the required result.

Uri uri  = new Uri(@"http://www.abc.com?refurl=/english/info/test.aspx?form=1&h=test&s=AB");
string query = uri.Query;

Which will give you :

?refurl=/english/info/test.aspx?form=1&h=test&s=AB

Later you can remove ?refurl= to get the desired output.

I am pretty sure there is no direct way in the framework for your particular requirement, you have to implement that in your code and that too with string operations.

2 Comments

It would not work if you would send more parameters (not only refurl)
@EvaldasDzimanavicius, off course it will not, but thats not in the question. Seems like the OP is interested in Query property of the Uri
1

I had similar situation some time ago. I solved it by encoding refurl value. now my url looks similar to that one: http://www.abc.com?refurl=adsf45a4sdf8sf18as4f6as4fd

I have created 2 methods:

public string encode(string);
public string decode(string);

Before redirect or where you have your link, you simple encode the link and where you are reading it, decode before use:

Response.redirect(String.Format("http://www.abc.com?refurl={0}", encode(/english/info/test.aspx?form=1&h=test&s=AB));

And in the page that you are using refurl:

 $refUrl = Request.QueryString["refurl"];
 $refUrl = decode($refUrl);

EDIT: encode/decode methods I actually have as extension methods, then for every string I can simply use string.encode() or string.decode().

1 Comment

you answer is also right. I am trying to use without encoding.
0

you should replace the & with &.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.