ASP.NET MVC:如何路由搜索术语。 (期间)结束

时间:2008-12-02 01:21:30

标签: .net asp.net-mvc model-view-controller routing period

当我尝试以.(句点)结束我的搜索字词结尾的请求时,我收到来自.Net MVC的404响应。这是我正在使用的路线:

routes.MapRoute(
                "Json",
                "Remote.mvc/{action}/{searchTerm}/{count}",
                new { controller="Remote", count=10}
            );

在搜索字词内搜索工作正常.,但它无法以此结束。有关如何路由此搜索请求的任何想法?

2 个答案:

答案 0 :(得分:23)

我已经解决了类似的问题(我遇到像/music/R.E.M这样的路径有问题。) 我已将以下行添加到system.webServer / handlers部分(根据您的情况调整):

 <add name="UrlRoutingHandler" type="System.Web.Routing.UrlRoutingHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" path="Remote.mvc/*" verb="GET"/>

我也注意到了,

<httpRuntime relaxedUrlToFileSystemMapping="true" />

仅当句点(。)位于中间斜杠对中(例如/ abc / de / f)时才起作用,并且当句点看起来像文件类型分隔符时不起作用(例如/ abc / de / fg) )。

答案 1 :(得分:5)

如果您使用的是.NET 4.0,则可以在web.config的system.web部分设置此标志,并允许它:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

我测试了它并且它有效。 Haack对此进行了解释。