Search code examples
c#asp.netquery-stringampersand

ASP.Net URLEncode - Ampersands Inside Query Strings


i have a query string like below :
Default.aspx?path=/Play & Game&AnotherQueryString=bla bla

the below URLEncode :

 lastpath = HttpUtility.UrlEncode(Request["path"].ToString());  

output is like this :

%2fPlay+

how can we handle ampersands inside query strings / those ampersands are not delimiters between query strings ?


Solution

  • You should encode the path before puting it in the query, because Request["path"].ToString() will always stop at the next &

    like that = Default.aspx?path=%2fPlay+%26+Game&AnotherQueryString=bla bla