How do I enable special characters in MVC routing?

痞子三分冷 提交于 2019-12-18 08:01:53

问题


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

回答1:


In web.config:

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

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




回答2:


The answer did not work for me. I had to use:

[ValidateInput(false)]
public ActionResult Index...

Hope this helps others.



来源:https://stackoverflow.com/questions/14009618/how-do-i-enable-special-characters-in-mvc-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!