您的位置:首页 > 其它

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

2015-10-21 00:00 656 查看

http://www.cnblogs.com/ToNi/p/4236910.html?utm_source=tuicool&utm_medium=referral

解决方案:

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

同时也可以给页面加上[code]<meta name="robots" content="nofollow" />
它的作用就是告诉蜘蛛我的动态元素不能被访问;

3记得给图片加alt属性,这是一个故事。所以导致了蜘蛛不接受图片但是接受图片的说明
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: