A lot of personal webmaster will use tools to generate their own site map, the disadvantage is that the site sitemap can not be updated in a timely manner. When we publish a new article, we should update the map of the site, and inform the search engine site map has changed!
First, let's look at how to generate a sitemap in ASP. In the first step, we complete the method of creating the node, as follows:
/// <summary>///Create a node/// </summary>/// <param name= "strURL" >Link Address</param>/// <param name= "Dlastmod" >Last Modified Time</param>/// <param name= "Strchangefreq" >Update Frequency</param>/// <returns>return node</returns>Private StaticXmlNode CreateNode (stringstrURL, DateTime dlastmod,stringstrchangefreq) {XmlNode Xnodeurl= xd. CreateElement ("URL"); XmlNode Nodeloc= xd. CreateElement ("Loc"); Nodeloc.innertext=strURL; Xnodeurl.appendchild (Nodeloc); XmlNode Nodelastmod= xd. CreateElement ("Lastmod"); Nodelastmod.innertext= Dlastmod.tostring ("yyyy-mm-ddthh:mm:ss+00:00"); Xnodeurl.appendchild (NODELASTMOD); XmlNode Nodechangefreq= xd. CreateElement ("Changefreq"); Nodechangefreq.innertext=Strchangefreq; Xnodeurl.appendchild (Nodechangefreq); returnXnodeurl;}
Next call the above method, traverse the website article, output the site map:
StaticXmlDocument xd =NewXmlDocument ();/// <summary>///Output Sitemap/// </summary>/// <param name= "article" >List<Article></param> Public Static voidWritesitemap (list<article>article) { stringstrfile = Httpruntime.appdomainapppath +"Xml/sitemap.xml"; XmlNode RootNode= xd. CreateElement ("Urlset"); XmlAttribute Attrxmlns= xd. CreateAttribute ("xmlns"); Attrxmlns.innertext="http://www.sitemaps.org/schemas/sitemap/0.9"; RootNode.Attributes.Append (ATTRXMLNS); //website HomeRootnode.appendchild (CreateNode ("http://www.lidongkui.com/", DateTime.Now,"Daily")); //create each article node <url></url> foreach(Article Aincharticle) {Rootnode.appendchild (CreateNode ("http://www.lidongkui.com/"+ A.urlname, A.addtime,"Monthly")); } xd. AppendChild (RootNode); Xd. InsertBefore (XD. Createxmldeclaration ("1.0","UTF-8",NULL), RootNode); Xd. Save (strfile);}
Finally, just get the article and call the method output site map:
XML. Writesitemap(db. Articles. OrderByDescending(+= m. ID). ToList());
To the successful output of the site map, but the output site map after the search engine does not find our site map changes, then we need to ping the search engines, the method is as follows:
//GoogleSystem.Net.WebRequest Reqgoogle =System.Net.WebRequest. Create ("http://www.google.com/webmasters/tools/ping?sitemap="+Httputility.urlencode ("Http://www.lidongkui.com/xml/sitemap.xml") ; Reqgoogle.getresponse ();//AskSystem.Net.WebRequest Reqask =System.Net.WebRequest. Create ("http://submissions.ask.com/ping?sitemap="+Httputility.urlencode ("Http://www.lidongkui.com/xml/sitemap.xml") ; Reqask.getresponse ();//YahooSystem.Net.WebRequest Reqyahoo =System.Net.WebRequest. Create ("http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url="+Httputility.urlencode ("Http://www.lidongkui.com/xml/sitemap.xml") ; Reqyahoo.getresponse ();//BingSystem.Net.WebRequest reqbing =System.Net.WebRequest. Create ("http://www.bing.com/webmaster/ping.aspx?siteMap="+Httputility.urlencode ("Http://www.lidongkui.com/xml/sitemap.xml") ; Reqbing.getresponse ();
Using these methods, when we published a new article in time to update our site map, while telling the search engine our site map has changed, which is more conducive to SEO.
Transferred from: Http://www.lidongkui.com/create-sitemap
ASP. NET Create Site Map