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
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
相关文章推荐
- 百度站点地图(百度sitemap)生成方法分享
- php生成百度sitemap站点地图类函数实例
- 分享一个在线生成站点地图SiteMap制作工具
- 用于WordPress的Google Sitemap xml自动生成站点地图插件
- 分享一个在线生成站点地图SiteMap制作工具
- php生成百度sitemap站点地图类函数实例
- C#生成sitemap站点地图
- 百度站点地图(百度sitemap)生成方法分享
- 温故知新ASP.NET 2.0(C#)(3) - SiteMap(站点地图)
- ASP.NET 站点地图(sitemap)简明教程
- CodeIgniter生成网站sitemap地图的方法
- .Net生成站点sitemap供百度抓取的类和使用
- Django:之Sitemap站点地图、通用视图和上下文渲染器
- [Asp.net]站点地图SiteMap
- 温故知新ASP.NET 2.0(C#)(3) - SiteMap(站点地图)
- asp.net中的站点地图sitemap
- phpcms如何生成地图sitemap静态页面
- 如何向Google、Yahoo!、MSN、Ask和百度提交在线生成的网站地图Sitemap
- C#中的站点地图文件夹web.sitemap