ASP.Net 4.0 对SEO增强一:使用MetaDescription,MetaKeywords,RedirectPermanant等

现在的网站对SEO越来越重视,有很多公司在做seo优化;换句话说SEO可以给网站主带来利益,做好了SEO,不需要付广告费就可以从搜索引擎带来更多的流量。鉴于此Asp.Net4.0对seo方面做了一些优化工作。

1. MetaDescription, MetaKeywords指定页面的meta 描述和关键字标签
我们可以在aspx文件的Page指令中指定:

1
2
3
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="OutputCacheTest.Default"
 MetaDescription="我是页面描述"
 MetaKeywords="关键字1,关键字2"%>

也可以在cs文件中指定,例如:

1
2
3
4
5
protected void Page_Load(object sender, EventArgs e)
{
    MetaDescription = "this is a test";
    MetaKeywords = "Asp.net 4.0,Cache";
}

2. 使用Response.RedirectPermanent告诉搜索引擎当前地址已经永久重定向了

在HttpResponse中新添加了RedirectPermanant方法和RedirectToRoutePermanent方法,这两个方法都可以实现301重定向,用来告诉搜素引擎当前访问的内容已经永久的移动到了另一个地址,这在程序改版修改了url规则时非常有用,使用举例如下:

1
2
3
4
5
6
7
8
9
10
11
protected void Page_Load(object sender, EventArgs e)
{
    //重定向到某个地址
    Response.RedirectPermanent("http://somedomain/somepath");
}
 
protected void Page_Load(object sender, EventArgs e)
{
    //重定向到RoutingUrl
    Response.RedirectToRoutePermanent(new { controller = "Test", action = "details", id = "2" });
}

3. 在.Net 4.0中RadioButtonList和CheckBoxList服务器端控件都支持用ul或ol标签做输出,例如

1
2
3
4
5
6
<asp:CheckBoxList runat="server" ID="list" RepeatLayout="OrderedList">
    <asp:ListItem Value="1">北京</asp:ListItem>
    <asp:ListItem Value="2">上海</asp:ListItem>
    <asp:ListItem Value="3">天津</asp:ListItem>
    <asp:ListItem Value="4">重庆</asp:ListItem>
</asp:CheckBoxList>

将输出

1
2
3
4
5
6
<ol id="list">
 <li><input id="list_0" type="checkbox" name="list$0" value="1" /><label for="list_0">北京</label></li>
 <li><input id="list_1" type="checkbox" name="list$1" value="2" /><label for="list_1">上海</label></li>
 <li><input id="list_2" type="checkbox" name="list$2" value="3" /><label for="list_2">天津</label></li>
 <li><input id="list_3" type="checkbox" name="list$3" value="4" /><label for="list_3">重庆</label></li>
</ol>

 

Asp.net 新特性相关阅读:

1. 从页面标记<%%>说起
2. Asp.Net 4.0 中可以用自定义的Provider做OutputCache 了
3. SEO增强支持MetaKeywords,和MetaDescription,RedirectPermanant
4. SEO增强之URL Routing
5. 输出更纯净的Html代码,ViewStateMode和ClientIDMode,CheckBoxList等

posted @   玉开  阅读(4077)  评论(12编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
点击右上角即可分享
微信分享提示