Reputation: 8266
I have an URL with the following format:
http://www.mysite.com/login.aspx?ref=~/Module/MyPage.aspx?par=1&par2=hello&par3=7
I use the content of the QueryString
it to Redirect
the user back to the page he was before logging in. In order to keep also the status of the page I need the parameters in the QueryString
. The number of parameters changes depending on the Page
calling the Login
and its status.
Let's say I want to store everything in the URL after ref
in the redirectURL
variable. I tried:
redirectURL = Request.QueryString("ref") // "~/Module/MyPage.aspx?par=1"
it gets everything after ref
but ignores everything after the &
(included). If I use:
redirectURL =Request.Url.Query // "ref=~/Module/MyPage.aspx?par=1&par2=hello&par3=7"
it gets everything, ref
included. In order to achieve my goal I need just to remove the first 4 characters from the redirectURL. But I think this solution is a bit "forced" and I am sure there should be some ASP.NET function that accomplish this task.
Upvotes: 1
Views: 3522
Reputation: 16144
Consider Encoding "~/Module/MyPage.aspx?par=1&par2=hello&par3=7
" before passing it to the url.
Eg.:
String MyURL = "http://www.mysite.com/login.aspx?ref=" +
Server.UrlEncode("~/Module/MyPage.aspx?par=1&par2=hello&par3=7");
And then, you can get the redirectURL using:
String redirectURL = Request.QueryString("ref");
Upvotes: 1
Reputation: 888167
The &
s in your URL are creating additional querystring arguments.
You need to escape the value of the ref
parameter before putting it in the querystring.
This will replace the &
s with %26
.
To do this, call Uri.EscapeDataString()
.
When you fetch the property from Request.QueryString
, it will automatically decode it.
Upvotes: 1