新闻建站cms系统、政府cms系统定制开发

广州网站建设公司-阅速公司

asp.net新闻发布系统、报纸数字报系统方案
/
http://www.ysneo.com/
广州网站建设公司
您当前位置:首页>网站技术

网站技术

如何对蜘蛛机器人添加缓存,OutputCache应该如何写缓存?

发布时间:2013/11/28 12:12:39  作者:Admin  阅读:294  

广告:阿里云采购优惠专区

如何对蜘蛛机器人添加缓存,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新闻系统购买咨询
扫描关注 广州阅速软件科技有限公司
扫描关注 广州阅速科技