SORU
21 Temmuz 2009, Salı


Devre dışı bırak tarayıcı tüm ASP.NET Web sitesi için önbellek

Bir tarayıcı önbelleğini devre dışı bırakmak için bir yöntem arıyorumtüm ASP.NET MVC web Sitesi

Aşağıdaki yöntemi buldum:

Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();

Ve ayrıca meta etiketi bir yöntem (bazı eylemler MVC Ajax, bir baş olmadan, meta etiketi ile kısmi HTML/JSON göndermek beri benim için hiçbir şey işe yaramaz).

<meta http-equiv="PRAGMA" content="NO-CACHE">

Ama bütün bir web sitesi için tarayıcı önbelleğini devre dışı bırakmak için basit bir yöntem arıyorum.

CEVAP
10 Kasım 2009, Salı


İActionFilter devralan bir sınıf oluşturun.

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

        base.OnResultExecuting(filterContext);
    }
}

Sonra gerekli nitelikler koydu

[NoCache]
[HandleError]
public class AccountController : Controller
{
    [NoCache]
    [Authorize]
    public ActionResult ChangePassword()
    {
        return View();
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ☆ SUB4SUB CENTER! ☆ spam here

    ☆ SUB4SUB

    22 ŞUBAT 2010
  • PorterRobinsonVEVO

    PorterRobins

    11 Kasım 2013
  • TopDJMag TV

    TopDJMag TV

    29 Temmuz 2010