2011-07-11 14 views
0

バックボタンをクリックしたときに実行する必要があるアクションメソッドがあります。私はこれまで、アクションメソッド(Response.Cache.SetCacheability(HttpCacheability.NoCache))でキャッシュを無効にしています。これは別のアクションメソッドでは機能しません。何らかの理由でキャッシュを無効にして戻るボタンを押すと。?ページが期限切れになった私のアクションメソッドは、問題があるかもしれないもの上の任意のアイデアをトリガするためにMVCバックボタンの問題

答えて

1

知る方法は、サーバー側で、ありませんページ要求が戻るボタンの結果であった場合

これまでのリクエストは、取得ではなく投稿であり、投稿にはあなたはデータを再投稿します。

+0

それは本当にポストです。ありがとう! – Quadwwchs

7

を以下のことを試してみてくださいすることは、私にとって素晴らしい作品:

public class NoCacheAttribute : ActionFilterAttribute 
{ 
    public override void OnResultExecuting(ResultExecutingContext filterContext) 
    { 
     var response = filterContext.HttpContext.Response; 
     response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); 
     response.Cache.SetValidUntilExpires(false); 
     response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); 
     response.Cache.SetCacheability(HttpCacheability.NoCache); 
     response.Cache.SetNoStore(); 
    } 
} 

public class HomeController : Controller 
{ 
    [NoCache] 
    public ActionResult Index() 
    { 
     // When we went to Foo and hit the Back button this action will be executed 
     // If you remove the [NoCache] attribute this will no longer be the case 
     return Content(@"<a href=""/home/foo"">Go to foo</a><div>" + DateTime.Now.ToLongTimeString() + @"</div>", "text/html"); 
    } 

    public ActionResult Foo() 
    { 
     return Content(@"<a href=""/home/index"">Go back to index</a>", "text/html"); 
    } 
} 
+0

面白そうです。ありがとう! – Quadwwchs