2017-04-13 83 views
1

RouteConfig.cs的HttpHandler在ASP.NET MVC 5.0

public static class RouteConfig 
    { 
     public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
      routes.IgnoreRoute("{*allaspx}", new {allaspx = @".*\.aspx(/.*)?"}); 
      routes.IgnoreRoute("{*allasmx}", new { allasmx = @".*\.asmx(/.*)?" }); 
      routes.IgnoreRoute("{*allsvc}", new { allsvc= @".*\.svc(/.*)?" }); 
      routes.IgnoreRoute("{*allFileAttachments}", new { allattachment = @".*\file.attachment(/.*)?" }); 
      ... 
      ... 
      ... 
     } 
    } 

的Web.config

<configuration> 
.... 
<system.web> 
<httpHandlers> 
<add path="*.attachment" verb="*" type="MyType, Namespace" /> 
</httpHandlers> 
</system.web> 
<system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
<remove name="attachmentHandler" /> 
     <add name="attachmentHandler" verb="*" path="*.attachment" type="myType, namespace" preCondition="integratedMode" /> 
</handlers> 
... 
</system.webServer> 
... 
</configuration> 

,當我嘗試訪問以下網址,它仍試圖找出控制器和失敗,404

http://localhost/somepath/file.attachment?4535345343

回答

1

這解決了這個問題。

<system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
    <add name="attachmentHandler" verb="*" 
       path="*.attachment" 
       type="myType, namespace" 
       resourceType="Unspecified" /> 
</handlers> 
... 
</system.webServer> 

參考MSDN - 要註冊的IIS 7.0中集成模式

運行HTTP處理程序