在 web.config 处理程序映射中指定应用程序根目录
我有一个带有 HttpHandler 的应用程序,用于处理对 .js 文件的任何请求。我只希望此处理程序处理应用程序根目录中请求的 *.js 文件。
处理程序映射如下所示:
<add name="HandleJS" path="*.js" verb="*" type="MyApp.JsHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
目前,此处理程序处理所有请求的 *.js 文件。这是我想要的行为的示例。
该请求将由处理程序处理:
http://localhost/myapps/approot/script.js
而这个不会 由处理程序处理:
http://localhost/myapps/approot/dontProcessMe/script.js
我真的希望避免在处理程序路径中包含完整的绝对路径,因此我首先尝试了其他一些操作。
add
元素的 path
属性看起来不允许使用 ~/
应用程序根机制,因此设置 path="~/*.js"
不起作用。
我还尝试复制内置于 IIS 中的 StaticFile 处理程序并执行以下操作:
<add name="MyStaticFiles" path="*/*.js" verb="*" modules="StaticFileModule" />
或
<add name="MyStaticFiles" path="dontProcessMe/*.js" verb="*" modules="StaticFileModule" />
两者都只返回 HTTP 状态为 200 的空白响应。
帮助我 Obi Wan Kenobi,你是我唯一的希望。
I have an application with an HttpHandler that processes any requests for a .js file. I only want this handler to process *.js files that are requested in the root of the application.
The handler mapping looks like this:
<add name="HandleJS" path="*.js" verb="*" type="MyApp.JsHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
Currently, this handler processes ALL requested *.js files. Here is an example of the behavior I want.
This request would be processed by the handler:
http://localhost/myapps/approot/script.js
and this one would not be processed by the handler:
http://localhost/myapps/approot/dontProcessMe/script.js
I'd really like to avoid including the full absolute path in the handler path so I tried some other things first.
It doesn't look like the path
property of the add
element allows the use of the ~/
application root mechanism, so setting path="~/*.js"
doesn't work.
I've also tried replicating the StaticFile handler that's built into IIS and doing something like this:
<add name="MyStaticFiles" path="*/*.js" verb="*" modules="StaticFileModule" />
or
<add name="MyStaticFiles" path="dontProcessMe/*.js" verb="*" modules="StaticFileModule" />
Both of which just return a blank response with an HTTP status of 200.
Help me Obi Wan Kenobi, you're my only hope.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不需要处理,可以检查处理程序本身中的 RequestURL 返回实际文件吗?
May be inspect the RequestURL in the handler itself return the actual file if there is no processing needed?
path="/*.js"
上没有骰子?默认情况下它应该使用相对路径...
No dice on
path="/*.js"
?It should be working with relative paths by default...