asp.net中如何使用微软的URLRewriter进行url重写
asp.net中如何进行url重写,今天研究了一天这个问题
想实现诸如:http://www.51cto.com/2008/2/2
http://www.51cto.com/default.html
等这种url
当然,程序直接生成静态页面可以实现的
但是那样要生成很多这种页面以及文件夹
而且在数据量大的情况下生成是很浪费时间的
在这种情况下就要实现url重写了,当然就很多种方法
下面介绍的是微软的URLRewriter方法
1.首先下载URLRewriter.dll,下载之后直接复制到你的网站的bin目录中
2.配置你的web.config文件
在<configuration>节点下加
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<!--一下三个是我自己写的测试的,当然你可以写很多个 -->
<!--这个是把http://localhost:2001/default.aspx?id=1 生成http://localhost:2001/d1.aspx 这种页面 -->
<RewriterRule>
<LookFor>~/d(\d{0,5})\.aspx</LookFor>
<SendTo>~/default.aspx?ID=$1</SendTo>
</RewriterRule>
<!--这个是把http://localhost:2001/article.aspx?id=1 生成http://localhost:2001/1/a.html 这种页面 -->
<RewriterRule>
<LookFor>~/(\d{0,5})/a\.html</LookFor>
<SendTo>~/article.aspx?id=$1</SendTo>
</RewriterRule>
<!--这个是把http://localhost:2001/test.aspx?id=1 生成http://localhost:2001/1/ 这种页面 -->
<RewriterRule>
相关文档:
在相同字符串的许多操作上,使用StringBuilder类会比使用String对象更有效率。
当你对一个string对象赋值时,这时会生成一个这个对象的副本,如果你赋值多次的话在系统中就会保存多个这个对象的副本,会对系统资源造成很大的浪费,但是StringBuilder不会出先上述情况
String数据类型代表的 ......
服务器控件 html标记
label----------<span/>
button---------<input type="submit"/>
textbox--------<input type="text"/>
linkbutton-----<a href="javascript:" />
imagebutton----<input type="image"/>
hyperlink------<a />
......
经过一个多月的准备,我的小站ASP.NET学习网(www.17aspx.com)终于上线了。界面图如下:
ASP.NET学习网(www.17aspx.com),为ASP.NET学习者提供教程、示例、源码、工具等学习资料,推动ASP.NET学习者之间的交流。涉及ASP.NET、ASP.NET MVC、LINQ、VS2010、WPF、Silverlight、C#3.5等方面。 ......
1、通过附加一个cookiecontainer到httprequest对象中,可以得到登录后返回的代表SESSION ID的COOKIE。
2、将此COOKIE包含在一个cookiecontainer中并附加到另一个HTTPREQUEST请求中,则可以实现SESSION的还原。
部分主要代码:
CookieContainer cookieContainer =& ......