2013-01-08 52 views
3

我們正在使用.net framework 4.0開發一個asp.net站點。並且我們試圖爲它輸入緩存。
但不幸的是,它沒有奏效。後來我們發現刪除Microsoft安全更新KB2656351將解決問題。
我想知道有沒有其他方式可以做到這一點,而無需刪除更新。輸出緩存不工作.net4.0

+1

我沒有遇到4.0的問題,請問您可以發佈您的配置嗎? – Nexus23

+0

安裝後發生的Microsoft安全更新KB2656351 –

回答

1

只有當您安裝上述提及更新並且響應中有一個cookie時,此問題才存在。無論Cookie是否包含在請求中。找到解決此問題的解決方法。我創建了一個自定義的HTTPModule,並將所有可用的cookie從響應(包括新添加的cookie)複製到Context.Items。然後清除響應中可用的所有Cookie。

在下一步中,讀取存儲在Context.items中的對象並將其添加回響應。所以當輸出緩存提供者試圖緩存頁面時,響應中沒有cookie。所以它照常運作。然後再添加cookies。

public void Init(HttpApplication context) 
    { 
     context.PostReleaseRequestState += new EventHandler(OnPostReleaseRequestState); 
     context.PostUpdateRequestCache += new EventHandler(OnPostUpdateRequestCache); 
    } 

    public void OnPostReleaseRequestState(Object source, EventArgs e) 
    { 
     HttpApplication application = (HttpApplication)source; 
     HttpContext context = application.Context; 
     HttpCookieCollection cookieCollection = new HttpCookieCollection(); 
     foreach (string item in context.Response.Cookies) 
     { 
      HttpCookie tempCookie = context.Response.Cookies[item]; 

      HttpCookie cookie = new HttpCookie(tempCookie.Name) { Value = tempCookie.Value, Expires = tempCookie.Expires, Domain = tempCookie.Domain, Path = tempCookie.Path }; 
      cookieCollection.Add(cookie); 
     } 
     context.Items["cookieCollection"] = cookieCollection; 
     context.Response.Cookies.Clear(); 
    } 

    public void OnPostUpdateRequestCache(Object source, EventArgs e) 
    { 
     HttpApplication application = (HttpApplication)source; 
     HttpContext context = application.Context; 
     HttpCookieCollection cookieCollection = (HttpCookieCollection)context.Items["cookieCollection"]; 
     if (cookieCollection != null) 
     { 
      foreach (string item in cookieCollection) 
      { 
       context.Response.Cookies.Add(cookieCollection[item]); 
      } 
     } 
    } 
0

對於此更新,報告有一些問題here,並且修復.net Framework 4工作。這可能是因爲.net Framework的損壞或者安裝了框架和IIS的順序,它們會註銷ASP.Net,所以我們需要專門註冊ASP.Net,這有時會導致這些問題。

我建議修復.Net框架,並註冊ASP.Net分開看看是否有效。

+1

我不這麼認爲,因爲如果我刪除所有的cookie,它的工作完美。 –