如何处理“ +”在asp.net mvc3路由? [英] how to deal "+" in asp.net mvc3 routes?

查看:72
本文介绍了如何处理“ +”在asp.net mvc3路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的路线:

  routes.MapRoute(
Tag,
tag / { t} / {action},
新的{controller = tag,action = unsolved}
);

链接如下:

 < a href = / tag / @(Uri.EscapeDataString(tagName))/ unsolved> @ tagName< / a> 

如果tagName不包含 +,则一切正常,否则,例如 http:// www.test.com/tag/c%2B%2B/unsolved\"(%2B来自@(Uri.EscapeDataString( +)),我收到错误消息:HTTP错误404.11-未找到



谁可以帮助我?谢谢!

解决方案

您可以尝试在< web.config的code>< system.webServer> 部分,因为我怀疑您仅在IIS 7中而不是在Visual Studio开发服务器中才有此问题(顺便说一句)您应该在问题中提到过)

 < system.webServer> 
< validate validateIntegratedModeConfiguration = false />
<模块runAllManagedModulesForAllRequests = true />
< security>
< requestFiltering allowDoubleEscaping = true />
< / security> ;
< /system.webServer>

进一步阅读: http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaspythings> ASP $ URL

my routes:

routes.MapRoute(
    "Tag",
    "tag/{t}/{action}",
    new { controller = "tag", action = "unsolved" }
    );

the link like:

<a href="/tag/@(Uri.EscapeDataString(tagName))/unsolved">@tagName</a>

if the tagName not contain "+",all work well , else ,like "http://www.test.com/tag/c%2B%2B/unsolved"(%2B come from @(Uri.EscapeDataString("+")),i get the error: HTTP error 404.11 - Not Found

who can help me? thanks!

解决方案

You may try allowing double escaping in the <system.webServer> section of your web.config as I suspect that you are having this problem only in IIS 7 and not in the Visual Studio development server (which by the way you should have mentioned in your question):

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
    <security>
        <requestFiltering allowDoubleEscaping="true"/>
    </security>
</system.webServer>

Further reading: http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx

这篇关于如何处理“ +”在asp.net mvc3路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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