HttpModule不会拦截IIS 5.1中的js和CSS文件 [英] HttpModule does not intercept js and css files in IIS 5.1
问题描述
我正在实现HttpModule来压缩请求.下面是HttpModule的编码:
I am implementing HttpModule for compressing request. Below is the codee for HttpModule:
public class Global : IHttpModule
{
public void Init(HttpApplication app)
{
app.PostReleaseRequestState += new EventHandler(app_PostReleaseRequestState);
}
void app_PostReleaseRequestState(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpContext context = app.Context;
string acceptEncoding = context.Request.Headers["Accept-Encoding"];
// If gzip is supported then gzip it else if deflate compression is supported then compress in that technique.
if (acceptEncoding.Contains("gzip"))
{
// Compress and set Content-Encoding header for the browser to indicate that the document is zipped.
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
context.Response.AppendHeader("Content-Encoding", "gzip");
}
else if (acceptEncoding.Contains("deflate"))
{
// Compress and set Content-Encoding header for the browser to indicate that the document is zipped.
context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
context.Response.AppendHeader("Content-Encoding", "deflate");
}
}
它能够在开发Web服务器中拦截和压缩js和css,但是当我从IIS 5.1运行它时它无法压缩js和css文件.请帮忙.
It's able to intercept and compress js and css in the development web server but when i run it from IIS 5.1 it is not able to compress js and css files. Please help.
推荐答案
我将确保.js和.css文件由.NET框架处理.
I would make sure that .js and .css files are handled by the .NET framework.
IIS 7和更高版本的参考可以在iis.net/ConfigReference/system.webServer/handlers中找到
The reference for IIS 7 and above can be found at iis.net/ConfigReference/system.webServer/handlers
关于IIS 6,您可以检查js和css是否在以下条件下处理:站点设置/主目录/应用程序设置/(应用程序池)配置/映射
Concerning IIS 6, you can check that js and css are handled under: Site settings / Home Directory / Application Settings / (Application Pool) Configuration / Mappings
这篇关于HttpModule不会拦截IIS 5.1中的js和CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!