asp.net 伪静态实现(UrlRewritingNet)

UrlRewritingNet.UrlRewriter源码地址 https://github.com/aspnetde/UrlRewritingNet
部署步骤:

步骤一:

 <!--只允许存在一个 <configSections> 元素,并且,如果存在该元素,它还必须是根 <configuration> 元素的第一个子元素-->
<configSections>
<!--步骤一,新静态规则应用添加-->
<section name="urlrewritingnet" requirePermission="false" type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
</configSections>

步骤二

  <!--步骤二,静态(system.web里面)-->
<httpModules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>

步骤三

 <!--步骤三,载入伪静态地址 任意标签后面-->
<urlrewritingnet configSource="UrlRewrites.config"></urlrewritingnet>

步骤四

<!--步骤四,部署在IIS上需要的配置-->
<system.webServer>
<handlers>
<!--一下根据.net版本选择不同的脚本 32位-->
<add name="静态脚本20" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
<add name="静态脚本40" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
   <!--64位-->
   <add name="net40伪静态" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
</handlers>
</system.webServer> 这里也可以在iis里面配置
处理映射->添加脚本映射-> [请求路径: *.html 执行文件 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll ]

  

步骤五   伪静态统一配置地址 》》 UrlRewrites.config

<!--伪静态统一配置地址-->
<urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString" defaultPage = "Default.aspx" defaultProvider="RegEx" xmlns="http://www.urlrewriting.net/schemas/config/2006/07" >
<rewrites>
<add name="cn_index" virtualUrl="~/b.html" destinationUrl="~/Demo.aspx" ignoreCase="true" />
<add name="1" virtualUrl="~/a-(\d+)-(.*).html" destinationUrl="~/Act.aspx?ActID=$1&Keyword=$2" />
</rewrites>
</urlrewritingnet>

源码

Demo.zip

http://localhost:28684/b.html -->http://localhost:28684/Demo.aspx

http://localhost:28684/a-1-测试.html --> http://localhost:28684/Act.aspx?ActID=1&Keyword=测试

 

上一篇:线上MySQL慢查询现象案例--Impossible WHERE noticed after reading const tables


下一篇:Android传感器概述-android学习之旅(七)