Reputation: 352
I need to send a redirect url as a query string parameter, unfortunately this url contains more than one querystring parameter as follows
"http://host:port/page2.aspx?param1=value¶m2=value¶m3=value"
the problem is when I encode this url and send it via querystring , it looks as if it wasn't encoded , so my application consider the redirect url parameter value to be only
"http://host:port/page2.aspx?param1=value"
and consider
"¶m2=value¶m3=value"
as a part of the current url
I tried Server.UrlEncode
and Server.HtmlEncode
Upvotes: 2
Views: 4628
Reputation: 1210
Replace '&' in your url with '%26' or use Server.UrlEncode
Responsse.redirect("redirectURL?a='http://url2?a=5%26b=7'&b=9'");
or
Responsse.redirect("redirectURL?a="+Server.UrlEncode("http://url2?a=5&b=7")+"&b=9'");
Upvotes: 0
Reputation: 9370
string myUrl = “http://host:port/page2.aspx?param1=value¶m2=value¶m3=value”;
string EncodedUrl = myUrl.EncodeTo64();
Pass this as querystring and retrieve using :
EncodedUrl.DecodeFrom64();
Functions:
public static string EncodeTo64(this string target)
{
byte[] toEncodeAsBytes
= System.Text.ASCIIEncoding.ASCII.GetBytes(target);
string returnValue
= System.Convert.ToBase64String(toEncodeAsBytes);
return returnValue;
}
public static string DecodeFrom64(this string target)
{
byte[] encodedDataAsBytes
= System.Convert.FromBase64String(target);
string returnValue =
System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
return returnValue;
}
Upvotes: 2