浅谈在静态页面上使用动态参数,会造成spider多次和重复抓取的解决方案

原因:

早期由于搜索引擎蜘蛛的不完善,蜘蛛在爬行动态的url的时候很容易由于网站程序的不合理等原因造成蜘蛛迷路死循环。

所以蜘蛛为了避免之前现象就不读取动态的url,特别是带?的url

解决方案:

1):配置路由

            routes.MapRoute("RentofficeList",
                            "rentofficelist/{AredId}-{PriceId}-{AcreageId}-{SortId}-{SortNum}.html",
                            new { controller = "Home", action = "RentOfficeList" },
                            new[] { "Mobile.Controllers" });
第一个参数是路由名称
第二个参数是路由的Url模式,参数之间用{}-{}方式分隔
第三个参数是一个包含默认路由的对象
第四个参数是应用程序的一组命名空间

2):设置连接

<a href="@Url.Action("RentofficeList",new RouteValueDictionary { { "AredId",0},{"PriceId",0},{"AcreageId",0},{"SortId",0},{"SortNum",0}})">默认排序</a>

对照上面的Url模式,依次写入参数赋值

3):获取参数


int areaId = GetRouteInt("AredId");//获取参数

///
<summary> /// 获得路由中的值 /// </summary> /// <param name="key"></param> /// <param name="defaultValue">默认值</param> /// <returns></returns> protected int GetRouteInt(string key, int defaultValue) { return Convert.ToInt32(RouteData.Values[key], defaultValue); } /// <summary> /// 获得路由中的值 /// </summary> /// <param name="key"></param> /// <returns></returns> protected int GetRouteInt(string key) { return GetRouteInt(key, 0); }

根据上面3个步骤操作,显示的url地址为:

http://localhost:3841/rentofficelist/3-0-0-0-0.html

这样就可以避免静态页面上使用动态参数,显示的页面都为静态页面

posted @ 2015-01-20 18:16  ToNiQian  阅读(1883)  评论(1编辑  收藏  举报