I have the following aspx link line that I would like to encode:
Response.Redirect("countriesAttractions.aspx?=");
I tried the following method:
Response.Redirect(Encoder.UrlPathEncode("countriesAttractions.aspx?="));
This is another method I've tried:
var encoded = Uri.EscapeUriString("countriesAttractions.aspx?=");
Response.Redirect(encoded);
Both are redirected to a page without an encoded URL:
http:
I tried this third method:
Response.Redirect(Server.UrlEncode("countriesAttractions.aspx?="));
This time the URL itself will be encoded:
http://localhost:52595/countriesAttractions.aspx%3F%3D
However, I get an error from the user interface:
HTTP Error 404.0 Not Found
The resource you are looking for has been removed, had its name changed, or
is temporarily unavailable.
Most likely causes:
-The directory or file specified does not exist on the Web server.
-The URL contains a typographical error.
-A custom filter or module, such as URLScan, restricts access to the file.
Also, I would like to encode another type of URL that includes parsing session strings:
Response.Redirect("specificServices.aspx?service=" +
Session["service"].ToString().Trim() + "&price=" +
Session["price"].ToString().Trim()));
The method with which I tried to include the encoding method in the code above:
Response.Redirect(Server.UrlEncode("specificServices.aspx?service=" +
Session["service"].ToString().Trim() + "&price=" +
Session["price"].ToString().Trim()));
The above encoding method that I used displayed the same results that I got using the previous encoding methods of the server url. I am not sure how to encode the URL correctly without getting errors.
, URL- CommandArgument:
Response.Redirect("specificAttractions.aspx?attraction=" +
e.CommandArgument);
:
Response.Redirect("specificAttractions.aspx?attraction=" +
HttpUtility.HtmlEncode(Convert.ToString(e.CommandArgument)));
.
, URL- ?
, - , , .
, stackoverflow, , .
AntiXSS , , , AntiXSS.
URL , , . .