中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

ASP.NET的SEO Linq to XML---網(wǎng)站地圖和RSS Feed

2019-03-08    來(lái)源:自由飛的Blog

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

網(wǎng)站地圖的作用是讓搜索引擎盡快的,更多的收錄網(wǎng)站的各個(gè)網(wǎng)頁(yè)。

這里我們首先要明白一個(gè)基本的原理,搜索引擎的爬行方式。整個(gè)互聯(lián)網(wǎng)就像一張縱橫交錯(cuò)的“網(wǎng)”:網(wǎng)的各個(gè)節(jié)點(diǎn)就是各個(gè)網(wǎng)頁(yè),而各個(gè)網(wǎng)頁(yè)之間通過(guò)url相互連接。蜘蛛可以從一個(gè)網(wǎng)頁(yè)出發(fā),通過(guò)該網(wǎng)頁(yè)上的url,爬到另一個(gè)網(wǎng)頁(yè);再通過(guò)另一個(gè)網(wǎng)頁(yè)上的url,再爬到更多的網(wǎng)頁(yè)……,以此類(lèi)推。但如果是一個(gè)新發(fā)布的網(wǎng)站,可能就沒(méi)有其他url指向它,那么它就永遠(yuǎn)不會(huì)被“爬到”(收錄)。為了解決這個(gè)問(wèn)題,新站可以自己主動(dòng)向搜索引擎提交url,申請(qǐng)蜘蛛前來(lái)抓。℅oogle申請(qǐng)網(wǎng)址:),但申請(qǐng)時(shí)一般只會(huì)提交一個(gè)主頁(yè)的url。

為了讓所有的url(尤其是動(dòng)態(tài)生成的)都能被蜘蛛快捷便利的檢索到,我們就需要提供一個(gè)全面完整、架構(gòu)清晰和更新及時(shí)的網(wǎng)站地圖。

和處理重復(fù)內(nèi)容的robots.txt文件,我們通過(guò).ashx文件來(lái)生成一個(gè)基于sitemaps.org的xml格式的網(wǎng)站地圖。網(wǎng)站地圖生成之后,我們就可以向Google等搜索引擎提交。大量的文章證實(shí),提交網(wǎng)站地圖將極大的提高網(wǎng)站的收錄速度和深度。其他幾乎所有的SEO方法,都有可能效果難以證實(shí)、失效甚至帶來(lái)副作用,但提交網(wǎng)站地圖除外!

Linq to XML為我們帶來(lái)了近乎完美的操作體驗(yàn)。

<%@ WebHandler Language="C#" Class="website" %>

using System;
using System.Web;
using System.Xml;
using System.Xml.Linq;
using System.Linq;

public class website : IHttpHandler {
    
    
public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "text/xml";

        
//文件的聲明信息,第第三個(gè)參數(shù)standalone的值yes 表示這個(gè) XML 文檔是自包含的(self-contained)而不依賴于外部所定義的一個(gè) DTD. 
        XDeclaration declaration = new XDeclaration("1.0""UTF-8""yes");
        context.Response.Write(declaration);
        
        
//XML文件的命名空間
        XNamespace ns = "http://www.google.com/schemas/sitemap/0.84";
        XElement siteMap = new XElement(ns + "urlset");

        
string fixedUrl = "http://www.freeflying.com/article";
        
string wholeUrl = string.Empty;
        
        
//循環(huán)取出數(shù)據(jù),轉(zhuǎn)換成XML節(jié)點(diǎn)
        foreach (var item in Articles.GetArticles())
        {
            XElement url = new XElement("url");

            wholeUrl = string.Format("{0}?id={1}&catelog={2}",fixedUrl,item.ID,item.Catelog); 
            XElement loc = new XElement("loc", wholeUrl);
            XElement lastmod = new XElement("lastmod", item.LastMod.AddDays(-23).ToShortDateString());
            XElement changefreq = new XElement("changefreq", item.Frequency);
            XElement priority = new XElement("priority", item.Weight);

            url.Add(loc, lastmod, changefreq, priority);

            siteMap.Add(url);
        }

        
        
        
//最后輸出整個(gè)xml文件
        context.Response.Write(siteMap);
    }
 
    
public bool IsReusable {
        
get {
            
return false;
        }
    }

}

同樣還將使用到xml技術(shù)的還有RSS

<%@ WebHandler Language="C#" Class="rss" %>

using System;
using System.Web;
using System.Xml;
using System.Xml.Linq;


public class rss : IHttpHandler {
    
    
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/xml";

        context.Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");

        XElement rssFeed = new XElement("rss"new XAttribute("version","2.0"));

        
string fixedUrl = "http://www.freeflying.com/article";
        
string wholeUrl = string.Empty;

        XElement channel = new XElement("channel",
            
new XElement("title""freeflying"),
            
new XElement("link", fixedUrl),
            
new XElement("description","the website for dream flying freely"),
            
new XElement("pubDate",DateTime.Now.ToString())
            );
        
        
        
foreach (var article in Articles.GetArticles())
        {
            XElement item = new XElement("item");

            XElement title = new XElement("title", article.Title);

            wholeUrl = string.Format("{0}?id={1}&catelog={2}", fixedUrl, article.ID, article.Catelog);
            XElement link = new XElement("link", wholeUrl);

            XElement description = new XElement("description", article.Description);

            XElement pubDate = new XElement("pubDate", article.LastMod.ToString());

            item.Add(title,link,description,pubDate);

            channel.Add(item);
        }

        rssFeed.Add(channel);

        context.Response.Write(rssFeed);

    }
 
    
public bool IsReusable {
        
get {
            
return false;
        }
    }
    

}

模擬數(shù)據(jù)

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.MobileControls;
using System.Collections.Generic;

/// <summary>
/// Summary description for Articles
/// </summary>
public class Articles
{
    
public Articles()
    {
        
//
        
// TODO: Add constructor logic here
        
//
    }

    
public static List<Article> GetArticles()
    {
        
return new List<Article>(){
            
new Article(234"blog", DateTime.Now.AddDays(-23), Freq.none, 0.8"asp.net seo""articles about SEO in asp.net"),
            
new Article(267"blog", DateTime.Now.AddDays(-245), Freq.daily, 0.6"ado.net pro","about the dataset usage"),
            
new Article(653"news", DateTime.Now.AddDays(-45), Freq.daily, 1,"CLR via C#","notebook about this book")
        };
    }


}

public class Article
{
    
public int ID;
    
public string Catelog;
    
public DateTime LastMod;
    
public double Weight;
    
public Freq Frequency;
    
public string Title;
    
public string Description;

    
public Article(int id, string catelog, DateTime lastMod, Freq frequency, double weight, string title, string description)
    {
        ID = id;
        Catelog = catelog;
        LastMod = lastMod;
        Weight = weight;
        Frequency = frequency;
        Title = title;
        Description = description;
    }
}

public enum Freq
{
    none = 1,
    daily = 2,
    weekly = 3,
}

作者:自由飛 原文鏈接

參閱自由飛其他的文章

ASP.NET的SEO:HTTP報(bào)頭狀態(tài)碼內(nèi)容重定向

asp.net的優(yōu)化服務(wù)器控件背后友好的Html和JS

ASP.NET的SEO:使用.ashx文件——排除重復(fù)內(nèi)容

標(biāo)簽: SEO ASP.NET XML 

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:如何挖掘長(zhǎng)尾關(guān)鍵詞

下一篇:ASP.NET的SEO:HTTP報(bào)頭狀態(tài)碼 內(nèi)容重定向