无法将 HttpHandler 映射到“path/*”通配符映射
所以我一直在尝试将 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 添加到该文件夹。
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>
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.
I'm sure I'm just "doing it wrong (tm)" but any help would be appreciated.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简单的。只需输入路径,不使用通配符。
这将匹配:
Simple. Just put the path, no wildcard.
This will match:
URLRoutingModule-4.0
是一个在 nancy 处理程序之前列出的捕获所有处理程序。因此,它会在你的处理者被击中之前发挥作用。您可以删除添加您的处理程序并将它们添加回来,如下所示:您可以在 IIS7 中的
Handler Mappings
下查看处理程序顺序,选择View Ordered List
,它将列出顺序其中它从上(第一个)到下(最后)加载处理程序。您可能需要在
/api
文件夹中添加第二个Web.config
类似地,这就是我通常对网站上的“/static”内容所做的操作。我还没有找到如何避免对秒 web.config 的需要。
编辑
当我不得不这样做时,我也很难弄清楚这一点,而且似乎我的记忆力不太好。我没有在任何地方指定
path/*
处理程序,而是这样:(仅指定简单的通配符/完全限定的路径来绕过 UrlRouting)
然后在我的
/Content/web.config
文件我设置了以下内容:/Content/
的处理程序列表现在如下所示:这几乎可以肯定
/Content/
中的任何内容都将通过 StaticFileModule 提供。这里的技巧似乎是指定:inheritInChildApplications="false"
。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:You can see the handler order in IIS7 under
Handler Mappings
selectView Ordered List
and it will list the order in which it loads the handlers top (first) to bottom (last).You might need a second
Web.config
in your/api
folderSimilarly, 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.
EDIT
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:(only specifying simple wildcards/fully qualified paths to go around UrlRouting)
Then in my
/Content/web.config
file I set the following:My handler list for
/Content/
looks like this now: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"
.看来 UrlRoutingModule-4.0 的麻烦比它的价值还要多。相反,我只是告诉 MVC3 忽略路由。这不是一个完美的解决方案,但在我有更好的解决方案之前,我必须在
RegisterRoutes
中坚持使用它:Seems the UrlRoutingModule-4.0 is more trouble than it is worth. Instead I've just told MVC3 to ignore the routes. Not a perfect solution but until I have something that works better I'll have to stick with this in
RegisterRoutes
: