无法映射一个HttpHandler到"路径/ *"通配符映射 [英] Unable to map an HttpHandler to a "path/*" wildcard mapping

查看:935
本文介绍了无法映射一个HttpHandler到"路径/ *"通配符映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我一直在试图映射一个HTTP模块到MVC3网站的子路径。它应该是pretty简单,因为我理解它,但它一直没有工作。该模块的设置,像这样:

So I've been trying to map an http module to a sub-path of an MVC3 site. It should be pretty simple as I understand it, but it has not been working. The module is setup like so:

<handlers>
  <add name="Nancy" path="api/*" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" allowPathInfo="true" />
</handlers>

一个匹配部分也有对IIS6这样我就可以在webdev.webserver运行它。然而测试(win7下),并与webdev.webserver都部署到我的本地IIS7,只/ API实际调用处理程序。如果我叫/ API / {}东西它只是返回一个404。

A matching section is also there for iis6 so I can run it under webdev.webserver. However testing both deploying to my local iis7 (under Win7) and with webdev.webserver, only /api actually calls the handler. If I call /api/{anything} it just returns a 404.

我敢肯定,我只是做是错误的(TM),但任何帮助,将AP preciated。

I'm sure I'm just "doing it wrong (tm)" but any help would be appreciated.

注:我也尝试一些其他的配置包括使用标签和创建/ API文件夹并添加一个web.config到该文件夹​​一个完整的通配符

Note: I've also tried a couple other configurations including using a tag and creating a /api folder and adding a web.config to that folder with a full wildcard.

推荐答案

URLRoutingModule-4.0 是一个包罗万象的南希处理程序之前的所有处理器上市。因此,它将开始发挥作用之前,你的处理程序是不断袭来。您可以删除处理程序添加你的并将它们添加回在像这样:

The URLRoutingModule-4.0 is a catch all handler listed before your nancy handler. It will thus come into play before your handler is ever hit. You can remove the handlers add yours and add them back in like so:

<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的处理顺序选择查看排序列表键,它会列出顺序在它加载处理器顶部(第一)到下(最后一个)。

You can see the handler order in IIS7 under Handler Mappings select View Ordered List and it will list the order in which it loads the handlers top (first) to bottom (last).

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

You might need a second Web.config in your /api folder

<?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>

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

Similarly, this is what I usually do for "/static" content on websites. I have not found out how to circumvent the need for the seconds web.config.

修改

我有一个很难搞清楚了这一点,当我不得不同时,似乎我的记忆处理不当使我受益匪浅。我不指定路径/ * 处理的任何地方,而不是我有这样的:

I had a hard time figuring this out when i had to as well and it seems my memory hasnt served me well. I dont specify a path/* handler anywhere instead I have this:

(仅指定简单通配符/完全合格的路径去解决UrlRouting)

(only specifying simple wildcards/fully qualified paths to go around 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, 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>
    </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>

我对处理程序列表 /内容/ 看起来像现在这样:

这大约是肯定,因为我可以在任何 /内容/ 将通过StaticFileModule服务。这里的技巧似乎被指定: inheritInChildApplications =FALSE

Which is about as sure as I can be anything in /Content/ will be served through StaticFileModule. The trick here seems to be specifying: inheritInChildApplications="false".

这篇关于无法映射一个HttpHandler到&QUOT;路径/ *&QUOT;通配符映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆