0

Sometimes values will have an "&" in them, and when this occurs, my syntax does not error, but it stops parsing the passed value at the "&". How can I handle the "&" character so that it keeps the string together?

http://www.bakedzititipsforanyonewithlittleknowledge/first.aspx?vax=Red%20&%20Black,Fire,House,Basket,Blanket

string fulladdress = HttpContext.Current.Request.Url.AbsoluteUri;
string encodedString = System.Web.HttpUtility.UrlEncode(fulladdress);
string Information = Request["vax"];
Information = Information.Replace("&", "%26");
Response.Write(vax);

And I am calling this from an external program so I can not use the + Server.UrlEncode(value)); at the end of my website in the call. I have to format a different way.

EDIT --- Sample output:
Red & Black
Fire
House
Basket
Blanket

What I am getting is
?vax=Red%20&%20Black
Fire
House
Basket
Blanket

  • 7
    http://stackoverflow.com/questions/561954/asp-net-urlencode-ampersand-for-use-in-query-string – Elliot Rodriguez Sep 24 '15 at 17:53
  • Can you please provide us your error?, and where it happens?. Normaly & character is for concatening variables in the request like > test.aspx?myname=juan&mysurname=rdc. – Juan Ruiz de Castilla Sep 24 '15 at 17:56
  • @JuanRuizdeCastilla - This is a peculiar instance as all values are passed in separated by a comma, then parsed out in the code-behind. The syntax works as it should with the exception of one of the fields containing a & – Ramalad Franklin Sep 24 '15 at 18:04
  • @RamaladFranklin, if you sure that have only one query parameter `vax` so you can just parse `HttpContext.Current.Request.Url.Query` as simple string – Grundy Sep 24 '15 at 18:10
  • @Grundy - where/how in my code-behind would I use that feature/function? – Ramalad Franklin Sep 24 '15 at 18:12
  • here you get full url `string fulladdress = HttpContext.Current.Request.Url.AbsoluteUri;`, if instead _AbsoluteUri_ you would be use `Query` you get string after question mark – Grundy Sep 24 '15 at 18:15
  • @Grundy - that will now permit the values to be passed, but the leading ? is left in as well as the %20& that was added for separating words. How can I remove that? – Ramalad Franklin Sep 24 '15 at 18:22
  • @RamaladFranklin, so just not encode this string. also can you provide expected output for your sample url? – Grundy Sep 24 '15 at 18:24
  • @RamaladFranklin, use [substring](https://msdn.microsoft.com/en-us/library/hxthx5h6(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2) before splitting – Grundy Sep 24 '15 at 20:02

0 Answers0