I have a default Asp.Net route as follows:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Nothing to special in it.
And I have my super simple default action in Home Controller:
public ActionResult Index(string id)
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
I can type the URL: http://localhost:12143/Home/Index/HanselandCratel
and it works fine but when I type in
http://localhost:12143/Home/Index/Hansel&Cratel
it doesn't
I understand & has to be encoded but when I type in:
http://localhost:12143/Home/Index/Hansel%26Cratel
it still doesn't work I get this error:
A potentially dangerous Request.Path value was detected from the client (&).
I am aware of setting this in web.config:
<httpRuntime targetFramework="4.5" requestPathInvalidCharacters="" />
but I am afraid I will have to sacrifice security when I do that.
Is there any other alternative to this? Perhaps any setting in Asp.Net?
&
in your URL? – kamil-mrzyglod