我想知道如何在asp.net MVC的url中有这样的东西
/Article/12.20.2013
我在下面尝试了它的工作正常/ Article / 12-20-2013但不适用于/Article/12.20.2013。我在Global.asax下面有
routes.MapPageRoute("Blog",
"/Article/{entryDate}",
new {controller = "Article", action = "Entry")};
我也尝试了类似下面的内容
routes.MapPageRoute("Blog",
"/Article/{month}.{Date}.{year}",
new {controller = "Article", action = "Entry")};
但没有运气..
请指导我一些样本。
答案 0 :(得分:2)
我认为问题在于IIS可能会将“.2013”视为文件扩展名并尝试为其找到处理程序。我们需要做的是让MVC处理所有请求。
如果您使用的是IIS 6,则需要对aspnet_isapi.dll
进行通配符映射。如果您使用的是IIS 7,则可以设置runAllManagedModulesForAllRequests="true"
:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
答案 1 :(得分:0)
您需要更改web.config以强制将以Article
开头的每个网址视为MVC网址
<system.webServer>
<handlers>
<add name="UrlRoutingHandler"
type="System.Web.Routing.UrlRoutingHandler,
System.Web, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
path="/Article/*"
verb="GET"/>
</handlers>
</system.webServer>
然后你的路由工作正常。