淺談在靜態頁面上使用動態參數,會造成spider多次和重複抓取的解決方案

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




同時也可以給頁面加上
<meta name="robots" content="nofollow" />
它的作用就是告訴蜘蛛我的動態元素不能被訪問;



3記得給圖片加alt屬性,這是一個故事。所以導致了蜘蛛不接受圖片但是接受圖片的說明
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章