Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable special characters in MVC routing?

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" }
         );
like image 656
Elad Benda Avatar asked Dec 23 '12 08:12

Elad Benda


People also ask

How do you handle special characters in MVC?

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" } );

Can you enable attribute routing in MVC?

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.

What are the three main elements of routing in MVC 3?

The three segments of a default route contain the Controller, Action and Id.

What is attribute routing in MVC?

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.


1 Answers

In web.config:

<system.web>
    <httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
    <pages validateRequest="false" />
</system.web>

Blatantly stolen from https://stackoverflow.com/a/6026291/299408

like image 81
Joshua Enfield Avatar answered Sep 29 '22 16:09

Joshua Enfield