ihttphandler 完全按原样写出文件
我正在编写一个继承自 IHttpHandler 的类,用于脚本和 css 组合。我只想在查询字符串定义了特殊参数时进行组合。如果未定义此参数,那么我想写入文件的内容,就好像处理程序根本不参与一样。完好无损地交付文件的最佳方式是什么?
EIDT:
我遇到的一个问题是,页面上有一个脚本标记,它引用虚拟目录中的脚本,但我所在的页面位于应用程序的子目录中。
引用控制脚本的页面位于 webserver/Admin/Default.aspx。当我访问实现 IHttpHandler 的类中的 Request 对象时,所有文件路径属性如下:webserver/Admin/~/SharedScripts/control.js。我该如何解决这个问题?
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. What is the best way to deliver the file unharmed?
EIDT:
The one problem I'm encountering is that I have a script tag on the page that refers to a script in a virtual directory but the page I am on is in a subdirectory of the application.
The page that the control script is being referenced from is located at 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在“ProcessRequest(HttpContext context)”方法中检查查询字符串参数,如下所示:
如果您想按原样流式传输请求的文件,则可以执行以下操作:
PS:您还可以查看以下代码项目文章以获取更全面的示例: http://www.codeproject.com/KB/locale/LocalizedScriptsAndStyles .aspx
You can check the query string parameter in the 'ProcessRequest(HttpContext context)' method like this:
If you want to stream the requested file as is you can then do the following:
PS: You can also check out the following code project article for a more comprehensive example: http://www.codeproject.com/KB/locale/LocalizedScriptsAndStyles.aspx