用URLRewriter重写url

用url重新一般都是使用URLRewriter库,基本上都是一些配置,在webconfig中

首先配置configuration节点

<configSections>
            <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter" />
    </configSections>

<system.webServer>节点下添加

<system.webServer>
<handlers>
   <add name="Rewriter" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" 
requireAccess
="None" preCondition="classicMode,runtimeVersionv4.0,bitness32" /> </handlers> </system.webServer>

 

接下来就是写规则了。在webconfig的configuration内部的最底部添加RewriterConfig节点,并写规则

 1 <!--url重写规则-->
 2     <RewriterConfig>
 3         <Rules>
 4             <!--圈子-->
 5             <RewriterRule>
 6                 <LookFor>~/(.*)/list/(.*)</LookFor>
 7                 <SendTo>~/group/circlelist.aspx?name=$1&amp;keyword=$2</SendTo>
 8             </RewriterRule>
 9             <RewriterRule>
10                 <LookFor>~/group/(.*)</LookFor>
11                 <SendTo>~/group/circle.aspx?name=$1</SendTo>
12             </RewriterRule>
13             <!--快速索引 字母-->
14             <RewriterRule>
15                 <LookFor>~/i/(.*)_(.*).html</LookFor>
16                 <SendTo>~/stock/indexing.aspx?i=$1&amp;page=$2</SendTo>
17             </RewriterRule>
18             <!--快速索引 型号列表-->
19             <!--<RewriterRule>
20                 <LookFor>~/(.*[^online,^askbuy,^ic,^services]).html</LookFor>
21                 <SendTo>~/stock/searchStock.aspx?keyword=$1</SendTo>
22             </RewriterRule>-->
23             <!--在线展会-->
24             <RewriterRule>
25                 <LookFor>~/online.html</LookFor>
26                 <SendTo>~/stock/onlineindex.aspx</SendTo>
27             </RewriterRule>
28             <!--求购专区-->
29             <RewriterRule>
30                 <LookFor>~/askbuy.html</LookFor>
31                 <SendTo>~/seller/askbuylist.aspx</SendTo>
32             </RewriterRule>
33             <!--IC圈子-->
34             <RewriterRule>
35                 <LookFor>~/ic.html</LookFor>
36                 <SendTo>~/member/icCircle.aspx</SendTo>
37             </RewriterRule>
38             <!--龙维商软服务-->
39             <RewriterRule>
40                 <LookFor>~/services.html</LookFor>
41                 <SendTo>~/stock/services.aspx</SendTo>
42             </RewriterRule>
43             <!--快速索引 型号列表-->
44             <RewriterRule>
45                 <LookFor>~/(.*).html</LookFor>
46                 <SendTo>~/stock/searchStock.aspx?keyword=$1</SendTo>
47             </RewriterRule>
48         </Rules>
49     </RewriterConfig>

 

这些基本上已经好了。但发布到iis上还需配置一些东西。即处理映射

选择你发布的网站。选择"处理程序映射"

 

技术分享

然后:

技术分享

选择路径:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

保存即可。

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。