使用微软URLRewriter.dll的url实现任意后缀名重写
2014-05-22 17:24
393 查看
<?xml version="1.0"?> <!--先引用URLRewriter.dll,放置于Bin目录--> <configuration> <configSections> <!--配置重写规则节点--> <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/> </configSections> <connectionStrings> <add name="TestConnectionString" connectionString="Data Source=.;Initial Catalog=Test;Integrated Security=True" providerName="System.Data.SqlClient"/> </connectionStrings> <!--重写规则--> <RewriterConfig> <Rules> <RewriterRule> <LookFor>~/product/([0-9]*)\.html</LookFor> <!--http://www.xxx.com/product/8001.html--> <SendTo>~/product.aspx?pid=$1</SendTo> <!--http://www.xxx.com/product.aspx?pid=8001--> </RewriterRule> <RewriterRule> <LookFor>~/product/([0-9]*)-([0-9]*)\.html</LookFor> <!--http://www.xxx.com/product/101-8001.html--> <SendTo>~/product.aspx?sid=$1&pid=$2</SendTo> <!--http://www.xxx.com/product.aspx?sid=101&pid=8001--> </RewriterRule> <RewriterRule> <LookFor>~/product/([0-9]*)/([0-9]*)\.html</LookFor> <!--http://www.xxx.com/product/101/8001.html--> <SendTo>~/product.aspx?sid=$1&pid=$2</SendTo> <!--http://www.xxx.com/product.aspx?sid=101&pid=8001--> </RewriterRule> </Rules> </RewriterConfig> <system.web> <httpHandlers> <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/> <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/> </httpHandlers> <compilation debug="true" targetFramework="4.0"/> </system.web> </configuration>
//利用Global.asax的Application_BeginRequest 实现url 重写 无后缀 void Application_BeginRequest(object sender, EventArgs e) { string oldUrl = System.Web.HttpContext.Current.Request.RawUrl; //获取初始url //~/123.aspx → ~/Index.aspx?id=123 Regex reg = new Regex(@"^\/\d+\.html"); if (reg.IsMatch(oldUrl)) { string id = reg.Match(oldUrl).ToString().Substring(1, reg.Match(oldUrl).ToString().LastIndexOf(".") - 1); Context.RewritePath("~/Index.aspx?id=" + id); } //~/123 → ~/Index.aspx?id=123 Regex reg1 = new Regex(@"^\/\d+$"); if (reg1.IsMatch(oldUrl)) { string id = reg1.Match(oldUrl).ToString().Substring(1); Context.RewritePath("~/Index.aspx?id=" + id); } //~/index/123 → ~/Index.aspx?id=123 Regex reg3 = new Regex(@"^\/index\/\d+$"); if (reg3.IsMatch(oldUrl)) { string id = reg3.Match(oldUrl).ToString().Substring(7); Context.RewritePath("~/Index.aspx?id=" + id); } }
相关文章推荐
- 使用微软URLRewriter.dll的url实现任意后缀名重写
- 微软URLRewriter.dll的url重写在.net简单使用
- 借助微软提供的url重写类库URLRewriter.dll(1.0)实现程序自动二级域名,域名需要泛解析
- 微软URLRewriter.dll的url重写的简单使用(实现伪静态)
- 使用UrlRewritingNet.Dll实现URL 重写
- 微软URLRewriter.dll的url重写在目标框架.Net Framework2.0、4.0和应用程序池经典模式、集成模式下的配置
- 使用IHttpHandler接口实现【不同路径+任意URL后缀重写到指定页面且URL地址不变】(附源码)_AX
- UrlRewritingNet.UrlRewriter.dll 重写url 在虚拟主机上使用
- 微软URLRewriter.dll的url重写的简单使用
- 【微软的URLRewriter】url重写实现任意二级域名或多级域名
- 使用RewritePath方法实现【不同路径+任意URL后缀重写到指定页面且URL地址不变】(附源码)_AX
- 使用IHttpHandler接口实现【不同路径+任意URL后缀重写到指定页面且URL地址不变】(附源码)_AX
- 微软URLRewriter.dll的url重写的简单使用
- 利用Intelligencia.UrlRewriter.dll实现URL重写2
- 微软URLRewriter.dll的url重写的简单使用
- asp.net用url重写URLReWriter实现任意二级域名
- 在ASP.Net2.0中使用UrlRewritingNet实现链接重写
- [转 ] asp.net用url重写URLReWriter实现任意二级域名
- URL重写之在IIS7中使用HttpModule,在IIS5和IIS6中使用 ISAPIRewrite实现无扩展名的URL重写(节选自福娃儿)
- asp.net用url重写URLReWriter实现任意二级域名