看到网上很多人在关于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&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>

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

拷贝 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;
第0个Key=list,value=1.1;第1个Key=word,value=2.33;