ASP.NET的SEO:Linq to XML---网站地图和RSS Feed

简介: 本系列目录网站地图的作用是让搜索引擎尽快的,更多的收录网站的各个网页。    这里我们首先要明白一个基本的原理,搜索引擎的爬行方式。整个互联网就像一张纵横交错的“网”:网的各个节点就是各个网页,而各个网页之间通过url相互连接。
本系列目录

网站地图的作用是让搜索引擎尽快的,更多的收录网站的各个网页。
    
这里我们首先要明白一个基本的原理,搜索引擎的爬行方式。整个互联网就像一张纵横交错的“网”:网的各个节点就是各个网页,而各个网页之间通过url相互连接。蜘蛛可以从一个网页出发,通过该网页上的url,爬到另一个网页;再通过另一个网页上的url,再爬到更多的网页……,以此类推。但如果是一个新发布的网站,可能就没有其他url指向它,那么它就永远不会被“爬到”(收录)。为了解决这个问题,新站可以自己主动向搜索引擎提交url,申请蜘蛛前来抓取(Google申请网址:),但申请时一般只会提交一个主页的url。

为了让所有的url(尤其是动态生成的)都能被蜘蛛快捷便利的检索到,我们就需要提供一个全面完整、架构清晰和更新及时的网站地图。( 网站地图的更多信息)。

和处理重复内容的robots.txt文件,我们通过.ashx文件来生成一个基于sitemaps.org的xml格式的网站地图。网站地图生成之后,我们就可以向Google等搜索引擎提交。大量的文章证实,提交网站地图将极大的提高网站的收录速度和深度。其他几乎所有的SEO方法,都有可能效果难以证实、失效甚至带来副作用,但提交网站地图除外!


Linq to XML为我们带来了近乎完美的操作体验。

img_405b18b4b6584ae338e0f6ecaf736533.gif WebSite
<% @ 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 " ;

        
// 文件的声明信息,第第三个参数standalone的值yes 表示这个 XML 文档是自包含的(self-contained)而不依赖于外部所定义的一个 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;
        
        
// 循环取出数据,转换成XML节点
         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);
        }

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

}

 

同样还将使用到xml技术的还有RSS

img_405b18b4b6584ae338e0f6ecaf736533.gif 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 ;
        }
    }
    

}

   

img_405b18b4b6584ae338e0f6ecaf736533.gif 模拟数据
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 ,
}


相关文章
|
8月前
|
存储 C# 数据库
.NET开源的在Windows上统计软件使用时长和网站浏览时长工具 - Tai
.NET开源的在Windows上统计软件使用时长和网站浏览时长工具 - Tai
|
4月前
|
Java PHP 开发工具
支付宝记---电脑网站支付(.NET)
支付宝记---电脑网站支付(.NET)
42 1
|
Docker 容器
.NET Core 网站项目在Docker中运行无法访问问题处理
.NET Core 网站项目在Docker中运行无法访问问题处理
273 0
|
7月前
|
XML 定位技术 PHP
织梦DedeCMS生成xml网站地图并自动更新的方法
织梦dedecms默认没有生成站点地图sitemap.xml文件的功能,不过我们可以自己通过简单的二次开发来给织梦增加这个功能
|
11月前
|
开发框架 供应链 前端开发
net基于asp.net的社区团购网站
社区团购系统依托社区团购系统和社区门店,是现在的一个重大市场和发展方向,通过研究企业在社区团购系统环境下的营销模式创新,对于普通的零售业和传统社区团购系统的转型发展具有重要的理论意义。随着互联网行业的发展,人们的生活方式发生着重大变化,人们越来越倾向于网络购物,这对传统企业来说如何把客户留下是一个重大挑战。就现在而言,由于社区团购的竞争已经进入最紧张激烈的阶段,有些团购平台甚至已经彼此之间打起了价格战,其中不乏有平台因为利润变少或资金链断裂而半途败亡。企业在实际的商业活动中,往往会面临许多等待优化的问题。因此,要在竞争激烈的市场中拔得头筹,必须重视提升对新商业模式的全面认知,科学于实际贴合的分
|
12月前
|
开发框架 安全 .NET
教你如何在WINDOWS Server2003上部署一个Asp.Net的网站
教你如何在WINDOWS Server2003上部署一个Asp.Net的网站
305 0
|
前端开发 NoSQL 关系型数据库
一个基于.Net Core开源个人博客网站
一个基于.Net 6开发的个人博客网站,功能完备。非常使用用来搭建个人博客、资源分享。
133 0
一个基于.Net Core开源个人博客网站
|
SQL 存储 开发框架
ASP.NET 使用语言集成查询 LINQ进行数据访问
ASP.NET 使用语言集成查询 LINQ进行数据访问
ASP.NET 使用语言集成查询 LINQ进行数据访问
|
开发框架 .NET 应用服务中间件
|
XML 开发框架 .NET
XML基础学习02&lt;linq to xml&gt;
XML基础学习02&lt;linq to xml&gt;
145 0
XML基础学习02&lt;linq to xml&gt;

相关课程

更多

相关实验场景

更多