Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
678 views
in Technique[技术] by (71.8m points)

c# - 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" }
         );
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In web.config:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...