asp.net – 无法将HttpHandler映射到“路径/ *”通配符映射

前端之家收集整理的这篇文章主要介绍了asp.net – 无法将HttpHandler映射到“路径/ *”通配符映射前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我一直在尝试将http模块映射到MVC3站点的子路径。它应该是很简单,因为我明白,但它没有工作。该模块的设置如下:
<handlers>
  <add name="Nancy" path="api/*" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" allowPathInfo="true" />
</handlers>

一个匹配的部分也是为了iis6,所以我可以在webdev.webserver下运行它。但是测试两个部署到我的本地iis7(在Win7下)和webdev.webserver,只有/ api实际上调用处理程序。如果我打电话给/ api / {anything},它只返回一个404

我相信我只是“做错了(tm)”,但任何帮助将不胜感激。

注意:我还尝试了一些其他配置,包括使用标签和创建/ api文件夹,并使用完整的通配符将web.config添加到该文件夹​​。

解决方法

URLRoutingModule-4.0是在你的nancy处理程序之前列出的所有处理程序。因此,在您的处理程序被击中之前,它将会发挥作用。你可以删除处理程序添加你的,并添加回如下:
<handlers>
    <remove name="BlockViewHandler" />
    <remove name="UrlRoutingModule-4.0" />
    <add verb="*" path="robots.txt" name="robots" type="System.Web.StaticFileHandler"/>
    ... custom handlers here
    <add name="Nancy" path="api/*" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" allowPathInfo="true" />
    ... now add back UrlRoutingModule and BlockViewHandler
    <add path="*" verb="*" name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule,System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" preCondition="managedHandler" />
    <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> 
</handlers>

您可以在“处理程序映射”中的IIS7中看到处理程序顺序,选择“查看有序列表”,它将列出将处理程序的顶部(第一个)加载到底部(最后)的顺序。

您的/ api文件夹中可能需要第二个Web.config

<?xml version="1.0"?>
<configuration>
    <system.web>
      <httpHandlers>
        <clear />
        <add name="Nancy" path="*" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" allowPathInfo="true" />
      </httpHandlers>
    </system.web>
</configuration>

同样,这是我通常在网站上的“/ static”内容。我还没有找到如何规避秒web.config的需要。

编辑

我很难想出这一点,当我不得不同样,似乎我的记忆没有给我很好的。我不指定一个路径/ *处理程序在任何地方,我有这个:

(只指定简单的通配符/完全限定的路径来围绕UrlRouting)

<location path="." inheritInChildApplications="false">
    <system.webServer>
        <!--
        ml: in .NET 4.0 its now safe to remove  from the modules section.
        Make sure you have a *. mapping to a ExtensionLessUrl hanlder in IIS
        this should improve performance a tad albeit neglectable.

        see: http://blogs.msdn.com/b/tmarq/archive/2010/04/01/asp-net-4-0-enables-routing-of-extensionless-urls-without-impacting-static-requests.aspx
        -->

        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="false" />
        <handlers>
            <remove name="BlockViewHandler" />
            <remove name="UrlRoutingModule-4.0" />
            <add verb="*" path="robots.txt" name="robots" type="System.Web.StaticFileHandler"/>
            .. Some company handlers i can't list 
            <add path="*" verb="*" name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule,PublicKeyToken=b03f5f7f11d50a3a" preCondition="managedHandler" />
            <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
    </system.webServer>
</location>

然后在我的/Content/web.config文件中,我设置如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <clear />
            <add name="StaticFiles" path="*" verb="*" modules="StaticFileModule" resourceType="Either" requireAccess="None" />
        </handlers>
        <staticContent>
            <clientCache cacheControlMaxAge ="31.00:00:00" cacheControlMode="UseMaxAge" />
        </staticContent>
    </system.webServer>
</configuration>

/ Content /的处理程序列表现在如下所示:

哪个是肯定的,我可以通过StaticFileModule提供/ Content /中的任何东西。这里的技巧似乎是指定:inheritInChildApplications =“false”。

原文链接:https://www.f2er.com/aspnet/253335.html

猜你在找的asp.Net相关文章