I'm using asp.net MVC 4.
These are my routes:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}"
);
My current controller responds to the following request correctly:
http://localhost:2020/PrivacyUrls/Details/ct14524
How can I validate urls like these?
http://localhost:2020/PrivacyUrls/Details/*ct14524
http://localhost:2020/PrivacyUrls/Details/&ct14524
which now returns 404.
A potentially dangerous Request.Path value was detected from the client (*).
A potentially dangerous Request.Path value was detected from the client (&).
I thought adding this route, but it didn't help:
routes.MapRoute(
"PivacyUrl/Details",
"PrivacyUrls/Details/{*ctid}",// URL with parameters
new { controller = "PrivacyUrls", action = "Details" }
);
I think the url http://.../home/index?id=a%2fb will work. To generate this url you need to change your route: routes. MapRoute( name: "Default", url: "{controller}/{action}", defaults: new { controller = "Home", action = "Index" } );
To enable Attribute Routing, we need to call the MapMvcAttributeRoutes method of the route collection class during configuration. We can also add a customized route within the same method. In this way we can combine Attribute Routing and convention-based routing. A route attribute is defined on top of an action method.
The three segments of a default route contain the Controller, Action and Id.
MVC 5 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web application. The earlier style of routing, called convention-based routing, is still fully supported.
In web.config:
<system.web>
<httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
<pages validateRequest="false" />
</system.web>
Blatantly stolen from https://stackoverflow.com/a/6026291/299408
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With