Sitemap(站点地图)你会生成吗?

文章转自: 爱符号  http://www.afuhao.com/article_articleId-178.shtml


Sitemap,顾名思义就是指网站的地图,主要是给谷歌、雅虎等搜索引擎的蜘蛛看的,了解你的网站有哪些栏目,有哪些文章。

一般是放在网站根目录的 sitemap.xml



ContentType:text/xml                注意一定要设置Response.ContentType="text/xml"; 否则就算你输出的是正确的XML格式,也不会被识别

ContentEncoding:UTF-8               注意这种文件类型的通用编码是utf-8,如果不设置成它,会有乱码的,Response.ContentEncoding=Encoding.UTF8;




参考网址:

http://www.afuhao.com/sitemap.shtml    请查看它的具体内容输出,这是动态页输出

http://www.afuhao.com/sitemap.xml       跟sitemap.shtml一样,不过它是生成的xml文件,是纯静态的。


下面来看看它的结构:


[xhtml] 
  1. xml version="1.0" encoding="utf-8" ?>  
  2. <urlset xmlns="http://www.google.com/schemas/sitemap/0.84">  
  3.       
  4.     <url>  
  5.         <loc>http://www.afuhao.com/article_titlePinyin-ASP.NETZhongShengChengrss.xmlNiHuiMa%EF%BC%9F_articleId-177_ArticleGroupId-43.shtmlloc>  
  6.         <lastmod>2013-04-19T06:39:33+08:00lastmod>  
  7.         <priority>0.5priority>  
  8.     url>  
  9.       
  10.     <url>  
  11.         <loc>http://www.afuhao.com/article_titlePinyin-NiYongC%23ZuoJiShiBenLiaoMa%EF%BC%9F_articleId-176_ArticleGroupId-42.shtmlloc>  
  12.         <lastmod>2013-04-17T18:41:50+08:00lastmod>  
  13.         <priority>0.5priority>  
  14.     url>  
  15. urlset>  


下面是动态页面的代码,不完整,仅供参考:

[xhtml] 
  1. <%@ Page Title="" Language="C#" %><%  
  2. //查询代码自己去想哦。  
  3. Response.ContentEncoding = Encoding.UTF8;  
  4. Response.ContentType = ContentTypes.Xml;  
  5. %>xml version="1.0" encoding="utf-8" ?>  
  6. <urlset xmlns="http://www.google.com/schemas/sitemap/0.84">  
  7.     <%foreach (Article item in q) {  
  8.           url = Symbol.HttpUtility.HtmlEncode(External.GetRemoteUrl(External.GetRemotingRootUrl("FrontResourcePoint", Html.ActionUrl("~/article", new { titlePinyin = item.TitlePinyin, articleId = item.Id, item.ArticleGroupId }))).AbsoluteUri);%>  
  9.     <url>  
  10.         <loc><%=url %>loc>  
  11.         <lastmod><%=item.ModifyDate.ToString("yyyy-MM-dd'T'HH:mm:sszzz", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))%>lastmod>  
  12.         <priority>0.5priority>  
  13.     url>  
  14.     <%} %>  
  15. urlset>  




看明白了吗?其实就是输出一下xml而已,别把它想得太复杂了。

没明白?再看一次。




文章转自: 爱符号  http://www.afuhao.com/article_articleId-178.shtml

你可能感兴趣的:(C#,ASP.NET,Web)