您的位置:首页 > 编程语言 > ASP

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

2013-07-05 21:58 411 查看
文章转自: 爱符号  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] 

<?xml version="1.0" encoding="utf-8" ?>  
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"><!--声明采用的是哪个架构,不同的架构不一样,百度的站点地图完全是另外一个结构-->  
      
    <url><!--一个网址-->  
        <loc>http://www.afuhao.com/article_titlePinyin-ASP.NETZhongShengChengrss.xmlNiHuiMa%EF%BC%9F_articleId-177_ArticleGroupId-43.shtml</loc><!--链接地址,其实就是location的缩写-->  
        <lastmod>2013-04-19T06:39:33+08:00</lastmod><!--最后更新时间,就是lastModify的缩写-->  
        <priority>0.5</priority><!--更新的频率,越是变化频繁的页面,频率就会越高-->  
    </url>  
      
    <url>  
        <loc>http://www.afuhao.com/article_titlePinyin-NiYongC%23ZuoJiShiBenLiaoMa%EF%BC%9F_articleId-176_ArticleGroupId-42.shtml</loc>  
        <lastmod>2013-04-17T18:41:50+08:00</lastmod>  
        <priority>0.5</priority>  
    </url>  
</urlset>  

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

[xhtml] 

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

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

没明白?再看一次。

文章转自: 爱符号  http://www.afuhao.com/article_articleId-178.shtml
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息