URL Rewriter

来源:互联网 发布:怎样在淘宝客服发图片 编辑:程序博客网 时间:2024/05/02 01:53
使用Url重写能给你网站带来哪些好处。

第一:有利于搜索引擎的抓取,因为现在大部分的搜索引擎对动态页面的抓取还比较弱,它们更喜欢抓取一些静态的页面。

   而我们现在的页面大部分的数据都是动态的显示的。这就需要我们把动态页面变成静态的页面,有利于搜索引擎的抓取。

第二:让用户更容易理解,很少有用户去关心你网站的页面的地址,但对一般的大中型网站增强可读性还是必须的。这样会让你的网站更加完美。

第三:隐藏技术的实现,我们可以通过Url重写可以实现技术的隐藏。不至于暴露你所采用的技术,给一些想攻击你网站的爱好者提供方便。

第四:可以很方便的重用,提高网站的移植性。如果我们后台方法改动的话,可以保证前台的页面部分不用改。这样就提高了网站的移植性。

它虽然有这么多的优点,但是也有一点缺点的,因为它是通过过滤器原理来实现的,就以为着又多了一道访问,会多少影响点访问速度的,这个可以忽略不计的。

Demo:

1.添加引用:Intelligencia.UrlRewriter 

2.web.config 新增。

<system.web>    <compilation debug="true" targetFramework="4.5" />    <httpRuntime targetFramework="4.5" />    <httpModules>      <add       type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"       name="UrlRewriter" />    </httpModules>  </system.web>

3.加入重写的规则节点:可用上正则

<rewriter>  <rewrite url="~/more/?$" to="~/MoreData.aspx" processing="stop" />  <rewrite url="~/rewrite/?$" to="~/UrlRewrite.aspx" processing="stop" /></rewriter>

4.加入模块化

<configSections>    <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />  </configSections>


5.引用rewrite config

 <rewriter file="~/Configuration/RewriteRules.config" />


More:http://www.cnblogs.com/yugen/archive/2010/08/18/1802776.html

0 0
原创粉丝点击