亚洲成av人片天堂网九九-国产精品成人av电影不卡-少妇无码专区视频网站-久久人人97超碰爱香蕉

新聞建站cms系統、政府cms系統定制開發

廣州網站建設公司-閱速公司

asp.net新聞發布系統、報紙數字報系統方案
/
http://www.plnongji.cn/
廣州網站建設公司
您當前位置:首頁>網站技術

網站技術

如何對蜘蛛機器人添加緩存,OutputCache應該如何寫緩存?

發布時間:2013/11/28 12:12:39  作者:Admin  閱讀:408  

廣告:

如何對蜘蛛機器人添加緩存,OutputCache應該如何寫緩存?

ASP.NET MVC Prevent OutputCache if request is from a spider

[OutputCache(Duration = 7200, VaryByParam = "none")]

如何對蜘蛛機器人添加緩存,應該如何寫緩存?

網站首頁被設置對任何請求是一樣的緩存。這里有個問題,如果是正常用戶訪問,網站則是正常的,如果第一次請求是從蜘蛛發起的,則情況不一樣了,網站首頁變成下載的頁面了 。

step 1. Load page with normal user agent. (Output cache caches the URL)

step 2. Load page with spider user agent. (the previous cached response is sent to the spider, and my Phantom JS filter never runs)

第一步:正常用戶客戶端,輸出緩存正常

第二步:蜘蛛機器人客戶端,緩存輸出是針對蜘蛛客戶端的。則首頁正常用戶訪問變成了下載。

解決方法:

Use VaryByCustom to force a 'Cache Miss' when the request is from a Search Engine Crawler(搜索引擎爬蟲).

In your Controller/Action:

[OutputCache(VaryByCustom="Crawler")]

public ActionResult Index()

{

// ...

return View();

}

Then in your Global.asax:

public override string GetVaryByCustomString(HttpContext context, string arg)

{

if (arg == "Crawler" && context.Request.Browser.Crawler)

return Guid.NewGuid().ToString();

return base.GetVaryByCustomString(context, arg);

}

廣告:

相關文章
OutputCache
蜘蛛
cms新聞系統購買咨詢
掃描關注 廣州閱速軟件科技有限公司
掃描關注 廣州閱速科技