使用 ASP.NET 4.0 和 IIS7 进行 HTTP 压缩

发布于 2024-10-17 14:24:44 字数 873 浏览 4 评论 0原文

一段时间以来,我一直在尝试在我的一些网站上实现 HTTP 压缩。

我尝试使用以下两种技术的变体来实现 HTTP 压缩:

From Application_BeginRequest in Global .asax

来自自定义 HttpModule

在这两种情况下,它最初似乎都有效。但是,当我浏览网站时,我很快就失去了 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

From a custom HttpModule

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↙厌世 2024-10-24 14:24:44

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

苦笑流年记忆 2024-10-24 14:24:44

虽然我在这里可能遇到了一些问题,但以下引用来自 演练:创建和注册自定义 HTTP 模块 似乎说明了这个问题:

<块引用>

如果 ASP.NET 应用程序在 IIS 6.0 下运行,则可以使用 HTTP 模块自定义对 ASP.NET 所服务的资源的请求。这包括 ASP.NET 网页(.aspx 文件)、Web 服务(.asmx 文件)、ASP.NET 处理程序(.ashx 文件)以及已映射到 ASP.NET 的任何文件类型。如果 ASP.NET 应用程序在 IIS 7.0 下运行,则可以使用 HTTP 模块自定义对 IIS 提供的任何资源的请求。这不仅包括 ASP.NET 资源,还包括 HTML 文件(.htm 或 .html 文件)、图形文件等。

正如我开始怀疑的那样,这是 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:

If the ASP.NET application is running under IIS 6.0, you can use HTTP modules to customize requests for resources that are serviced by ASP.NET. This includes ASP.NET Web pages (.aspx files), Web services (.asmx files), ASP.NET handlers (.ashx files), and any file types that you have mapped to ASP.NET. If the ASP.NET application is running under IIS 7.0, you can use HTTP modules to customize requests for any resources that are served by IIS. This includes not just ASP.NET resources, but HTML files (.htm or .html files), graphics files, and so on.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文