hetal gala
hetal gala

Reputation: 249

Getting query string parameter value having '&' in it in C#

I am passing url as follows ...

Response.Redirect("~/all-media/books/?serachtext=on&off");

where serachtext is the only parameter. So, when I access this parameter as follows, it gives me only "on" as value.

Request.QueryString["searchtext"]

So, how can I solve this?

Upvotes: 0

Views: 817

Answers (2)

Simon Whitehead
Simon Whitehead

Reputation: 65079

This won't work. The ampersand needs to be URL encoded.

The URL encoded value for an ampersand is %26. SO you can do either:

a)

Response.Redirect("~/all-media/books/?serachtext=on%26off");

or b)

Response.Redirect("~/all-media/books/?serachtext=" + HttpUtility.UrlEncode("on&off"));

Upvotes: 5

Guffa
Guffa

Reputation: 700362

You should encode the value that you put in the query string:

Response.Redirect("~/all-media/books/?searchtext=" + Server.UrlEncode("on&off"));

Or do it manually:

Response.Redirect("~/all-media/books/?searchtext=on%26off");

Upvotes: 0

Related Questions