第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

禁用整個(gè)ASP.NET網(wǎng)站的瀏覽器緩存

禁用整個(gè)ASP.NET網(wǎng)站的瀏覽器緩存

慕哥9229398 2019-06-21 14:49:36
禁用整個(gè)ASP.NET網(wǎng)站的瀏覽器緩存我正在尋找一種方法來禁用瀏覽器緩存整個(gè)ASP.NETMVC網(wǎng)站我發(fā)現(xiàn)了以下方法:Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);Response.Cache.SetNoStore();還有一個(gè)元標(biāo)記方法(它對我不起作用,因?yàn)橐恍㎝VC操作通過Ajax發(fā)送部分HTML/JSON,而沒有Head,meta標(biāo)記)。<meta http-equiv="PRAGMA" content="NO-CACHE">但我正在尋找一個(gè)簡單的方法,以禁用整個(gè)網(wǎng)站的瀏覽器緩存。
查看完整描述

3 回答

?
躍然一笑

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));

HttpContext.Current.Response.Cache.SetValidUntilExpires(false);

HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

HttpContext.Current.Response.Cache.SetNoStore();

所有請求都會首先通過default.aspx進(jìn)行路由-所以假設(shè)您可以彈出后面的代碼。


查看完整回答
反對 回復(fù) 2019-06-21
?
泛舟湖上清波郎朗

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊

創(chuàng)建從IActionFilter繼承的類。

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);
    }}

然后把屬性放在需要的地方.。

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


查看完整回答
反對 回復(fù) 2019-06-21
?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

與其使用你自己的東西,不如簡單地使用為你提供的東西。

如前所述,不要禁用所有的緩存。例如,應(yīng)該緩存ASP.NETMVC中大量使用的jQuery腳本。實(shí)際上,理想情況下,您應(yīng)該使用CDN但我的觀點(diǎn)是,應(yīng)該緩存一些內(nèi)容。

我發(fā)現(xiàn)這里最有效的方法是使用一個(gè)類,而不是到處撒[OutputCache]:

[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]public class NoCacheController  : Controller{}

您希望禁用緩存的所有控制器,然后從該控制器繼承。

如果需要覆蓋NoCacheController類中的默認(rèn)值,只需在操作方法上指定緩存設(shè)置,操作方法上的設(shè)置將優(yōu)先。

[HttpGet][OutputCache(NoStore = true, Duration = 60, VaryByParam = "*")]public ViewResult Index(){
  ...}


查看完整回答
反對 回復(fù) 2019-06-21
  • 3 回答
  • 0 關(guān)注
  • 746 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號