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

本系列目录

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

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

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

 

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

ExpandedBlockStart.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

ExpandedBlockStart.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 ;
        }
    }
   

}

   

ExpandedBlockStart.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 ,
}

 

posted on 2015-01-08 23:22  v.e.n.u.s 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/jx270/p/4212131.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
网优宝(woyobo)seo企业网站管理系统采用asp.net(C#) + ACC2003构架,全站基于seo核心开发,使用div+css 2.0设计界面,全站使用伪静态设置。内置多个个性系统:企业简介系统(自由添加),新闻发布系统,产品发布系统,在线订单系统,在线留言功能,网站地图,定时发布系统,招聘系统,在线交流,友情链接,模板系统,绝对地址,全站标签自由设置,自动生成标签,锚文本自动添加,长尾单自动生成等。所有操作均可在后台进行。 网优宝是国内首款基于seo友好性的seo企业网站管理系统,让企业网上推广易如反掌。 网优宝seo企业网站管理系统主要优势: 一、 全站功能实现与seo的有机结合,使网站推广更容易,更简单 a) 全站结合seo原理开发的独有技术,一键使用绝对地址,伪静态设置,锚文本自动添加,文章产品定时发布,全站标签自由设置, 全站使用 div+cs布局,一键生成网站地图,长尾单自动生成与锚文本添加。大大节省工作,提高效率 b) 网优宝seo企业网站管理系统使搜索更容易,推广更简单。有个网优宝提升关键词排名就是那么简单。 二、 操作简单,网站可随意更改,个性网站就是那么简单 a) 本系统使用asp.net 2.0技术对模板进行封装,程序自带操作手册,只需要简单复制黏贴就可以实现个性网站布局。 b) 后台操作简单,采用树形结构,不论懂不懂网络,皆可根据后台文字提示对网站内容进行更新与管理。 三、 支持在线修改,易于实现,登陆后台即可修改你想要的效果 本功能采用IO文件流技术,实现在线对文件的修改,编辑功能,图片的预览,无需登陆FTP下载文件,即可实现修改。 四、 支持多风格界面与展现形式的相互切换,只要修改css文件即实现对模板的修改。 a) 网站内置多套模板,可根据喜好自由切换,模板易于修改,让你网站个性十足。 b) 模板不但实现了传统的风格切换,还实现了整站布局切换,只要对现有模板进行修改即可实现个性模板的制作,只要稍懂div+css即可制作个性模板,模板任意上传修改,删除。 五、 系统功能强大灵活,让不懂网站的人也可以做出个性网站 a) 内置多个系统模块:简介、文章、产品、留言、订单、招聘和搜索等系统 b) 产品类别无限制分类,树形显示,用户体验增加 c) 后台信息自由删除、编辑、添加。 d) 功能模块,全部捆绑操作,您可以做您想做的,开始个性建站之旅。 六、 交互式营销,让您的网站随时为客户服务 a) 后台自由添加在线聊天工具:比如QQ b) 可后台在线添加在线统计功能,简单方便。 c) 订单与留言及时查看,做生意就是这么简单。 七、 安全稳定 a) 使用asp.net2.0 + ACC 架构,程序完全原创,使网站更安全。 b) 程序自带权限设置手册,让你网站更安全。 c) 验证码、防刷新机制、SQL过滤设置和防注入功能,让您的网站安全无忧 八、 一次授权,终身使用,强大的技术团队支持 a) 网优宝为机械专家网技术部开发,历时半年之久,反复测试-修改, b) 网优宝有强大的技术团队提供技术支持,所有反馈问题会在24小时内及时处理 c) 网优宝已获得版权(专利号:2010SR043669) d) 机械专家网有专门的团从事于网站优化,网站建设,有强大的技术团队保证服务的质量。 优化人员为什么选择网优宝? 1. 网优宝基于seo开发,所有功能的实现皆与seo结合 2. 网优宝目的在于提高优化人员的工作量,提高工作效率 3. 网优宝的所有功能全部符合优化人员的优化习惯 4. 优化人员想的,网优宝全部做到了 程序员为什么选择网优宝? 1. 网优宝自带模板修改上传编辑功能,稍微修改便可实现网站改版 2. 网优宝所有功能均以封装,前台只需要布局即可实现功能调用 3. 大大节省程序员的工作量 企业为什么选择网优宝? 1. 网优宝后台功能操作简单,只要会打字就会建站,易于维护 2. 网优宝自带操作手册,网优宝教你如何优化网站 3. 企业只需要做简单的工作量即可实现网站优化、关键词排名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值