栏目导航
热点推荐
- 如何配置Web.config文件 for ASP
- .NET小常识——答你所问
- ASP.NET程序中常用的三十三种代
- 一个“简单”的ASP.NET的服务器
- ASP.NET中使用AJAX中的方式
- 从N层到.NET详细剖析原理(2)
- 十项必须学习的.NET技术
- Visual Basic中文本框处理技巧集
- 几十个ASP.NET性能优化的常用方
- ASP.NET技术FAQ
- Asp.Net细节性问题精萃
- 十天学会ASP.net之第一天
阅览排行
ASP.NET重写URL地址,主要利用UrlRewriter组件
www.jz123.cn 2009-02-15 来源: 中国建站会员投稿 网客心飞 我要投递新闻
本文版权归学IT网(www.xueit.com)所有,任何单位与个人转载必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
本文基本ASP.NET技术,重写URL不需要IIS设置。
本教程目的,利用UrlRewriter重写组件来重写URL地址,来达到SEO,隐藏URL参数。
首先下载UrlRewriter
下载地址:http://down.chinaz.com/soft/23286.htm
下面以一个简单的实例来做应用:
第一、把下载好的Intelligencia.UrlRewriter.dll文件放到程序目录bin
再到vs.net项目中添加Intelligencia.UrlRewriter.dll文件引用
第二、新建一个index.aspx文件
index.aspx.cs内容如下:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Request["pid"]);
}
也就是说输出参数pid的内容
第三、配置Web.config文件
内容如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--设置地址重写组件-->
<configSections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>
</configSections>
<!--地址重写规则文件-->
<rewriter file="~/App_Data/rewrite.xml"/>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="false">
</compilation>
<authentication mode="Windows" />
<!--httpModules-->
<httpModules>
<add type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter" name="UrlRewriter" />
</httpModules>
</system.web>
</configuration>
第四、开始实例应用
第一种效果实验:
正常访问:http://localhost:4412/index.aspx?pid=hao
重写URL为:http://localhost:4412/index_hao.aspx
重写规则文件rewrite.xml内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<rewriter>
<!-- ([a-zA-Z]+) 只允许英文 -->
<rewrite url="~/index_([a-zA-Z]+).aspx$" to="~/index.aspx?pid=$1" processing="stop" />
</rewriter>
原访问效果图:
重写效果图:
第二种效果实验:
正常访问:http://localhost:4412/index.aspx?pid=hao
重写URL为:http://localhost:4412/index/任意字符.aspx
重写规则文件rewrite.xml内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<rewriter>
<!-- ([a-zA-Z]+) 只允许英文 -->
<rewrite url="~/index_([a-zA-Z]+).aspx$" to="~/index.aspx?pid=$1" processing="stop" />
<!-- (.*)任意字符 -->
<rewrite url="~/index/(.*)\.aspx$" to="~/index.aspx?pid=$1" />
</rewriter>
效果图如下:
实验成功,是不是很简单呢!!欢迎多多交流,学it网会出更多原创作品。
上一篇:在VB.NET中利用Split和Replace函数计算字数 下一篇:Asp.net通过MySql.Data.dll操作mysql数据库