我如何能够在MVC路由特殊字符? [英] How do I enable special characters in MVC routing?

查看:142
本文介绍了我如何能够在MVC路由特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用asp.net MVC 4。

这是我的路线:

  routes.MapRoute(
         名称:默认,
         网址:{控制器} / {行动} / {ID}
         );

我的电流控制器响应以下要求正确:

的http://本地主机:2020 / PrivacyUrls /细节/ ct14524

我如何可以验证网址,像这样的?

的http://本地主机:2020 / PrivacyUrls /细节/ * ct14524

的http://本地主机:2020 / PrivacyUrls /细节/&放大器; ct14524

现在返回404。

从客户端(*)中检测到有潜在危险的Request的值。

从客户端检测到有潜在危险的Request的值(安培)。

我想加入这条路线,但它并没有帮助:

  routes.MapRoute(
         PivacyUrl /详细信息,
         PrivacyUrls /细节/ {*} CTID,// URL带参数
         新{控制器=PrivacyUrls,行动=详细信息}
         );


解决方案

在web.config中:

 <&的System.Web GT;
    &所述;的httpRuntime requestPathInvalidCharacters =requestValidationMode =2.0/>
    <页validateRequest =假/>
< /system.web>

从大摇大摆 http://stackoverflow.com/a/6026291/299408

被盗

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

解决方案

In web.config:

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

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

这篇关于我如何能够在MVC路由特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆