【问题标题】:httpHandler in ASP.NET MVC 5.0ASP.NET MVC 5.0 中的 httpHandler
【发布时间】:2017-09-09 17:22:56
【问题描述】:

我的RouteConfig.cs

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>

当我尝试访问以下 URL 时,它仍会尝试查找控制器并失败并显示 404

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

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-routing httphandler


    【解决方案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 处理程序

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 2022-02-02
      • 1970-01-01
      相关资源
      最近更新 更多