asp.net mvc的不接收,在它一个时期的GET请求 [英] asp.net mvc does not receive the GET request with a period in it
问题描述
我使用.net4.5rc与MVC4.0rc
I'm using .net4.5rc with MVC4.0rc
在code以下是从MVC应用程序的WebAPI拍摄,但我同样的行为是有reular asp.net MVC
The code below is taken from a MVC webapi application but I the same behaviour is there for reular asp.net mvc
我的RegisterRoutes code看起来像这样
My registerroutes code looks like this
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "R1",
routeTemplate: "product/{id}",
defaults: new {
controller="Product",
id = RouteParameter.Optional
}
);
这与不具有在其中一个周期的ID效果很好。然而,当我问在这一个时期的产物,电话似乎没有得到ASP.NET
This works well with Ids that doesn't have a period in them. However when I ask for a product with a period in it, the call does not seem to get to ASP.NET
当我用下面的设置上时,有一个尾随它的工作原理类似职位的建议/
不过,这并不没有它的工作
when I use the setting below as suggested on similar posts it works when there is a trailing / But it doesn't work without it
在总结
http://mysite.com/product/AZ0 //works
http://mysite.com/product/AZ.0/ //work with relaxedUrlToFileSystemMapping
http://mysite.com/product/AZ.0 //does not work
的响应是404,我想这是由IIS不涉及ASP.NET返回。
当我运行routedebugger用类似上面的最后一个网址,我甚至不得到routedebugger东西
The response is 404 and I guess this is returned by IIS without involving ASP.NET. When I run routedebugger with a URL like the last one above, I don't even get the routedebugger stuff
如何使IIS传递控制ASP.NET时,有带图案的网址:
mysite.com/product/{id}不管是否有一段在id或不
How do I make IIS to pass the control to ASP.NET when there is a URL with a pattern: mysite.com/product/{id} regardless of whether there is a period in the id or not.
感谢。
推荐答案
让我这个回答我自己。添加URL重写解决了这个问题。
下面添加到web.config的code告诉后面带有一个/如果URL的形式为(产品/的 的),然后,它不再是一个处理改写网址文件,但作为普通MVC处理。
Let me answer this myself. Adding a URL Rewrite solves the problem. The code below added to the web.config tells to rewrite the Url with a trailing "/" if the URL is of the form (product/.) Then it is no longer handled as a file but handled as regular MVC.
<system.webServer>
....
<rewrite>
<rules>
<rule name="Add trailing slash" stopProcessing="true">
<match url="(product/.*\..*[^/])$" />
<action type="Rewrite" url="{R:1}/" />
</rule>
</rules>
</rewrite>
</system.webServer>
这篇关于asp.net mvc的不接收,在它一个时期的GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!