我使用 HTTP 模块来压缩请求,这是我的实现:
void context_Begin(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
string encoding = app.Request.Headers.Get("Accept-Encoding");
if (encoding == null)
return;
Stream baseStream = app.Response.Filter;
if (encoding.Contains("gzip"))
{
app.Response.Filter = new GZipStream(baseStream, CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "gzip");
}
else if (encoding.Contains("deflate"))
{
app.Response.Filter = new DeflateStream(baseStream, CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "deflate");
}
}
所以一切都很好,只是主网址的奇怪行为:
除主 URL 外,所有页面都运行良好,我的主 URL 是:www.mynewsite.com,如果我禁用 HTTP 模块,一切都很好,但是启用它时,我得到主 URL 的 404 错误:找不到资源。
我不明白?这个页面和请求压缩有什么关系?
有人对此有任何想法吗?有什么建议吗?