I am trying to encode <
and >
in a MVC parameter, tried using encodeURIComponent, however the decoding seem to occur prior to reaching the controller and it blows up the routing
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Default",
"Home/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
http://localhost/HomeStretch/Home/ListAll?Value=%22%7B%3Cdbid%3E%7BD576959C-31F8-469B-9C23-17B046DF590F%7D%3Cdbid%3E%7D%22"
If I take away the <>
carets it works, if I leave them in the call fails. I can do my own silly conversion using a *
instead of %
, however I am wondering if there is a better way of getting around this?
Turns out this maybe a security issue, I was scouring the event log and found below exception had been thrown. How do I properly insulate my tags, so this won't happen?
Exception information:
Exception type: HttpRequestValidationException
Exception message: A potentially dangerous Request.QueryString value was detected from the client (Filters[0].Value=""{<dbid>{D576959C-31F8...").
at System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)
at System.Web.HttpValueCollection.GetValues(String name)