使用 ASP.NET 4.0 和 IIS7 进行 HTTP 压缩
一段时间以来,我一直在尝试在我的一些网站上实现 HTTP 压缩。
我尝试使用以下两种技术的变体来实现 HTTP 压缩:
From Application_BeginRequest in Global .asax
在这两种情况下,它最初似乎都有效。但是,当我浏览网站时,我很快就失去了 CSS 样式。并且浏览器报告 JS 文件包含无效字符。而且,在某些时候,整个网站完全变成了胡言乱语。
我当然希望我知道这里发生了什么。有人有什么建议吗?是因为这些技术仅适用于旧版本的 ASP.NET/IIS 吗?
编辑:我无权访问 IIS,也不应该需要它。随着 ASP.NET 和 IIS 的最新迭代,越来越多的控制权被赋予了 web.config,而无需触及 IIS。这应该得到完全支持,而无需深入研究 IIS,事实上,上面的两个链接声称他们能够做到这一点。我就是无法让它为我工作。
编辑:经过进一步检查,使用上面第二个链接中的代码(HTTP 模块),我可以看到正在为我网站上的所有文件类型调用模块处理程序。这显然是问题的一部分。 (请注意,在某些情况下,整个页面会变成垃圾,这表明存在其他问题。)任何人都可以建议什么决定哪些文件发送到 HTTP 处理程序,或者为什么该链接处的代码可能对其他人有效,但对我无效?
I've been trying to implement HTTP compression on a few of my sites for some time now.
I've tried implementing HTTP compression using variations on the following two techniques:
From Application_BeginRequest in Global.asax
In both cases, it initially seems to work. But, as I navagate around the site, I quickly lose my CSS styling. And the brower reports a JS file contains invalid characters. And, at some point, the entire site turns entirely to jibberish.
I sure wish I knew what was happening here. Does anyone have any suggestion? Is it because these techniques only work on older versions of ASP.NET/IIS?
EDIT: I do not have access to IIS, and should not require it. With the latest iterations of ASP.NET and IIS, more and more control is being given to web.config without touching IIS. This should be fully supported without delving into IIS and, in fact, the two links above claim they are able to do just this. I just can't get it to work for me.
EDIT: On further inspection, using the code in the second link above (the HTTP module), I can see the module handler is being called for all file types on my site. This is clearly part of the problem. (Note that, in some cases, the entire page turns to garbage, which suggests other problems.) Can anyone suggest what determines which files are sent to the HTTP handler, or why the code at that link might work for someone else but not me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IIS 7 本身支持压缩 - 不应该可以是任何需要的编码。除非您尝试在尚未启用它的托管提供商上实现它,但您的问题中没有明确说明这一点
IIS 7 supports compression natively - there should not be any coding required. Unless, perhaps, you are trying to implement it on a hosting provider that has not enabled it, but that is not made clear in your question
虽然我在这里可能遇到了一些问题,但以下引用来自 演练:创建和注册自定义 HTTP 模块 似乎说明了这个问题:
正如我开始怀疑的那样,这是 ASP.NET 4.0 和 IIS7 中的更改。正如我多次提到的,这些正在变得越来越集成。上面的引用表明 HTTP 模块现在可以处理 IIS 提供的所有文件类型。
这就是为什么旧代码对我不起作用。解决方法似乎是简单地从我的处理程序中检查文件类型。
While I may have had a few issues going on here, the following quote from Walkthrough: Creating and Registering a Custom HTTP Module seems to illuminate the problem:
As I was beginning to suspect, this is a change in ASP.NET 4.0 and IIS7. As I've mentioned several times, these are becoming more and more integrated. And the quote above suggests that HTTP modules now handle all files types served by IIS.
So that's why the older code doesn't work for me. And the fix appears to be to simply check the file type type from my handler.