から取り出されたときに6ASP.Net - 腐敗で使用GZIP結果がASP.Net 2.0とIISを使用してキャッシュ
IがのIHttpModuleを拡張し、Web.configファイルに登録して圧縮を有効
public class EnableCompression : IHttpModule
{
public void Init(HttpApplication application)
{
application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
}
private void Application_BeginRequest(Object source, EventArgs e)
{
HttpContext context = HttpContext.Current;
String encoding = context.Request.Headers.Get("Accept-Encoding");
if (encoding == null)
return;
encoding.ToLower();
if (encoding.Contains("gzip"))
{
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
HttpContext.Current.Response.AppendHeader("Content-Encoding", "gzip");
}
else
{
context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
HttpContext.Current.Response.AppendHeader("Content-Encoding", "deflate");
}
}
void IHttpModule.Dispose()
{
throw new Exception("The Method or Operation is not Implemented");
}
}
ザ私もexpiresヘッダー設定した後、私のマスターページのコードファイル
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
Response.Cache.SetExpires(DateTime.Now.AddMinutes(10));
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetLastModified(DateTime.Now);
}
にページロードイベントでヘッダーを有効期限が切れる設定するまで上記のは、私は眉一度ゴミの束を得るだけで正常に動作しますserはキャッシュからデータを取得します。最初にページが読み込まれたときには、それは問題ありません。私は圧縮を無効にしますが、ヘッダーを満了したままにすると、それは 大丈夫です
��`I�%&/m�{J�J��t��`$ؐ@�����iG#)�*�
私は、ヘッダーを満了し無効にした場合:私は新しいページに移動してから戻って最初のページになった場合、私は唯一の完全なページを取得します圧縮は有効にしておいてください。 両方を有効にすると、ページにガベージがいっぱい表示されます。
何が起こっているのか分かりません。
Response Header
HTTP/1.1 200 OK
Date: Sun, 08 Jan 2012 07:23:15 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Encoding: gzip
Cache-Control: private
Expires: Sun, 08 Jan 2012 07:33:00 GMT
Last-Modified: Sun, 08 Jan 2012 07:23:00 GMT
Vary: *
Content-Type: text/html; charset=utf-8
Content-Length: 13613
Request Header
GET /eng/DE/ HTTP/1.1
Host: wwwnpg
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Cookie: ASP.NET_SessionId=gxdxwnnum5rumue13rxmc5mb
は、この答えはあなたの質問に対処します。http://stackoverflow.com/a/20253179/1026459 –