1. 程式人生 > >ASP.NET中的URL改寫辦法

ASP.NET中的URL改寫辦法

例如:想訪問http://127.0.0.1:8888/mobile/list_1.html

實質上是訪問http://127.0.0.1:8888/mobile/list.aspx?id=1

如何實現?

1、URLRewriter.dll引入系統;

2、Web.config 檔案放

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

<configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
   。。。。。。等等引數
  </configSections>

裡面

3、Web.config 檔案放

<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>

 <httpModules>
      <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
     。。。。。。等等引數
    </httpModules>

4、Web.config檔案放

<add name="UrlRewrite" path="*.aspx" verb="GET,POST" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" />

<handlers>

</handlers>

5、Web.config檔案放

<RewriterConfig>
        <Rules>
            <RewriterRule>
                <LookFor>~/mobile/list_(\d{1,})\.html</LookFor>
                <SendTo><![CDATA[~/mobile/list.aspx?ProductsCode=$1]]></SendTo>
            </RewriterRule>
            
        </Rules>
    </RewriterConfig>