IHttpHandler请求对象和虚拟目录问题
我正在编写一个继承自 IHttpHandler 的类,用于脚本和 css 组合。我只想在查询字符串定义了特殊参数时进行组合。如果未定义此参数,那么我想写入文件的内容,就好像处理程序根本不参与一样。我遇到的一个问题是,我在页面上有一个脚本标记,该标记引用虚拟目录中的脚本,但我正在访问的页面位于应用程序的子目录中。
I am writing a class that inherits from IHttpHandler for script and css combining. I only want to combine if the querystring has a special parameter defined. If this parameter is not defined then I want to write the contents of the file as if the handler wasn't even involved. The one problem I'm encountering is that I have a script tag on a page that refers to a script in a virtual directory but the page I am hitting is in a subdirectory of the application.
The page that the control script is being referenced from is located at http://webserver/Admin/Default.aspx. When I access the Request object in the class that implements IHttpHandler all file path properties are the following: webserver/Admin/~/SharedScripts/control.js. How do I resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您需要
ResolveUrl
方法,但没有Page
或任何与此相关的控件。 这篇文章解释了如何在没有Page<的情况下做到这一点/code> 手头的物体。
Basically, you need the
ResolveUrl
method, but you don't have aPage
, or any controls for that matter. This article explains how to do that without aPage
object at hand.这是我想出的解决方案:
This is the solution I came up with: