views:

533

answers:

2

I have a request to a page that looks like /doSomthing?a=that&ret=url however now i need to login so i must do something like /login?ret=/doSomthing?a=that&ret=url This doesnt work as well as one may hope so how do i correctly escape the return URL then unescape it?

I am using ASP.NET with C#

+2  A: 

You can do that by passing the target url through the UrlEncode method in the HttpServerUtility class. Example use, within a Page class:

string urlEncoded = Server.UrlEncode(this.Request.RawUrl);
Fredrik Mörk
+2  A: 

You should URL encode the querystring part, which can be done using the UrlEncode method of the HttpUtility class:

 HttpUtility.UrlEncode(yourString);
driis