UrlRewriter 使用详解 (Friendly Url)

看到网上很多人在关于 UrlRewriter上花了很多时间,其实很简单,无外呼也就两种方法.
1.下载 UrlRewriter.DLL组件
    IIS服务器上,也有很多商业的ISAPI 筛选器模块可供使用
2.利用.NET的自带的类实现
   

    首先设置WebConfig中的内容
   
 1 <? xml version = " 1.0 " ?>
 2 < configuration >
 3      < configSections >
 4      < section name = " CustomConfiguration "  type = " URLRewriter.Config.UrlsSection, URLRewriter "   />
 5    </ configSections >
 6
 7    < CustomConfiguration >
 8      < urls >
 9        < add virtualUrl = " ~/list/(\d+) "  destinationUrl = " ~/default.aspx?list=$1 "   />
10        < add virtualUrl = " ~/list/(\d+)/ "  destinationUrl = " ~/default.aspx?list=$1 "   />
11        < add virtualUrl = " ~/list/(\d+)/index.html "  destinationUrl = " ~/default.aspx?list=$1 "   />
12        < add virtualUrl = " ~/word/(\d+)/index.html "  destinationUrl = " ~/default.aspx?word=$1 "   />
13        < add virtualUrl = " ~/list/(.*)/word/(.*)/index.html "  destinationUrl = " ~/default.aspx?list=$1&amp;word=$2 "   />
14    
15        < add virtualUrl = " ~/microsoft*.* "  destinationUrl = " ~/default.aspx "   />
16        < add virtualUrl = " ~/microsoft* "  destinationUrl = " ~/default.aspx "   />
17        < add virtualUrl = " ~/m/i/c/rosoft.aspx "  destinationUrl = " ~/default.aspx "   />
18        < add virtualUrl = " ~/m/i/c/* "  destinationUrl = " ~/default.aspx "   />
19      </ urls >
20    </ CustomConfiguration >
21
22      < system.web >
23          < httpModules >
24              < add type = " URLRewriter.RewriterModule, URLRewriter "  name = " RewriterModule " />
25          </ httpModules >
26          < authentication mode = " Forms " />
27      </ system.web >
28 </ configuration >

拷贝 UrlRewriter_bin 重写类 中的DLL 到BIN文件夹内

使用相当方便
URL: http://localhost:2064/list/1.1/word/2.33/index.html
 /list/1.1/word/2.33/index.html
第0个Key=list,value=1.1;第1个Key=word,value=2.33;

你可能感兴趣的:(urlrewrite)