cel*_*lik 8 iis asp.net-mvc asp.net-mvc-routing iis-7.5 asp.net-web-api
我正在使用.net4.5rc和MVC4.0rc
下面的代码来自MVC webapi应用程序,但我对reular asp.net mvc的行为相同
我的registerroutes代码看起来像这样
 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapHttpRoute(
                name: "R1",
                routeTemplate: "product/{id}",
                defaults: new { 
                                controller="Product",
                                id = RouteParameter.Optional 
                              }
            );
这适用于没有句号的Ids.但是,当我要求一个带有句号的产品时,调用似乎没有进入ASP.NET
当我在类似的帖子上使用下面的设置时,它会在有尾随时起作用/但如果没有它就不起作用
综上所述
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.当我用上面的最后一个URL运行routedebugger时,我甚至没有得到routedebugger的东西
当存在带有模式的URL时,如何使IIS将控件传递给ASP.NET:mysite.com/product/{id},无论id是否有句点.
谢谢.
我自己回答一下.添加URL重写可以解决问题.添加到web.config中的以下代码告诉如果URL是表单(product/.),则用尾随"/"重写Url 然后它不再作为文件处理,而是作为常规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>
| 归档时间: | 
 | 
| 查看次数: | 1365 次 | 
| 最近记录: |