ASP.NET MVC 5.0 中的 httpHandler
httpHandler in ASP.NET MVC 5.0
我的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
这解决了问题。
<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 处理程序
我的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
这解决了问题。
<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 处理程序