熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

淺談.NET重寫URL

2022-06-13   來源: .NET編程 

  具體使用方法

  首先nfig的配置

  <?xml version=?><configuration> <configSections>

  <section name=RewriterConfig type=URLRewriterConfigRewriterConfigSerializerSectioHandlerURLRewriter />

  </configSections>

  <RewriterConfig> <Rules> <RewriterRule> <LookFor>~/ListCategories\aspx</LookFor>

  <SendTo>~/Defaultaspx</SendTo> </RewriterRule> <RewriterRule>

  <LookFor>~/(\d+)l</LookFor> <SendTo>~/Coveraspx?id=$</SendTo> </RewriterRule> </Rules>

  </RewriterConfig> <systemweb> <httpModules>

  <add type=URLRewriterModuleRewriter URLRewriter name=ModuleRewriter/> </httpModules>

  <compilation debug=true/></systemweb>

  </configuration>

  主要配置的代碼是這些其他的根據自己的需要的版本自行添加

  然後DefaultaspxCoveraspx新建個頁面

  Defaultaspx

  <%@ Page Language=C# AutoEventWireup=true CodeFile=Defaultaspxcs Inherits=_Default %>

  <!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

  <html xmlns=><head runat=server>

  <title>無標題頁</title></head><body> <form id=form runat=server>

  <div>

  <a >ListCategoriesaspx</a>

  <a >l</a> </div> </form></body><

  /html>Coveraspx

  <%@ Page Language=C# AutoEventWireup=true CodeFile=Coveraspxcs Inherits=Cover %>

  <%@ Register TagPrefix=skm Namespace=ActionlessForm Assembly=ActionlessForm %>

  <!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

  <html xmlns=><head runat=server>

  <title>Cover</title></head><body> <skm:form id=form runat=server>

  <div> Cover頁面 <h><a javascript:void() onclick=historygo()>返回上一頁</a></h>

  <asp:Button ID=Button runat=server Text=Button />

  </div>

  </skm:form></body></html>Coveraspxcs

  using System;

  using SystemCollections;

  using SystemConfiguration;

  using SystemData;

  using SystemLinq;

  using SystemWeb;using SystemWebSecurity;

  using SystemWebUI;

  using SystemWebUIHtmlControls;

  using SystemWebUIWebControls;

  using SystemWebUIWebControlsWebParts;

  using SystemXmlLinq;public partial class Cover : SystemWebUIPage{

  protected void Page_Load(object sender EventArgs e)

  {

  if (RequestQueryString[id] == null)

  {

  ResponseEnd();

  }

  else

  {

  int id = ConvertToInt(RequestQueryString[id]); ResponseWrite(id);

  }

  }

  }

  還要去對iis設置

  這樣的話偽靜態就可以用了

  C:\WINDOWS\MicrosoftNET\Framework\v\aspnet_isapidll 這是上面的路徑

  浏覽Defaultaspx頁

  ListCategoriesaspx 頁面其實在服務器上面是沒有的它裡面的內容是Defaultaspx的內容因為配置文件裡面設置了

  具體使用方法

  首先nfig的配置

  <?xml version=?><configuration> <configSections>

  <section name=RewriterConfig type=URLRewriterConfigRewriterConfigSerializerSectioHandlerURLRewriter />

  </configSections> <RewriterConfig> <Rules> <RewriterRule> <LookFor>~/ListCategories\aspx</LookFor>

  <SendTo>~/Defaultaspx</SendTo> </RewriterRule> <RewriterRule>

  <LookFor>~/(\d+)l</LookFor> <SendTo>~/Coveraspx?id=$</SendTo>

  </RewriterRule> </Rules> </RewriterConfig>

  <systemweb> <httpModules> <add type=URLRewriterModuleRewriter URLRewriter name=ModuleRewriter/>

  </httpModules> <compilation debug=true/>

  </systemweb>

  </configuration>

  主要配置的代碼是這些其他的根據自己的需要的版本自行添加

  然後DefaultaspxCoveraspx新建個頁面

  Defaultaspx

  <%@ Page Language=C# AutoEventWireup=true CodeFile=Defaultaspxcs Inherits=_Default %>

  <!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

  <html xmlns=><head runat=server>

  <title>無標題頁</title></head><body> <form id=form runat=server>

  <div>

  <a >ListCategoriesaspx</a>

  <a >l</a> </div> </form></body>

  </html>Coveraspx

  <%@ Page Language=C# AutoEventWireup=true CodeFile=Coveraspxcs Inherits=Cover %>

  <%@ Register TagPrefix=skm Namespace=ActionlessForm Assembly=ActionlessForm %>

  <!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

  <html xmlns=><head runat=server>

  <title>Cover</title></head><body>

  <skm:form id=form runat=server> <div> Cover頁面 <h><a javascript:void() onclick=historygo()>返回上一頁</a>

  </h>

  <asp:Button ID=Button runat=server Text=Button />

  </div>

  </skm:form>

  </body>

  </html>Coveraspxcs


  using System;

  using SystemCollections;

  using SystemConfiguration;using SystemData;

  using SystemLinq;

  using SystemWeb;

  using SystemWebSecurity;

  using SystemWebUI;

  using SystemWebUIHtmlControls;

  using SystemWebUIWebControls;

  using SystemWebUIWebControlsWebParts;

  using SystemXmlLinq;public partial class Cover : SystemWebUIPage

  {

  protected void Page_Load(object sender EventArgs e)

  {

  if

  (

  RequestQueryString[id] == null)

  {

  ResponseEnd();

  }

  else

  {

  int id = ConvertToInt(RequestQueryString[id]); ResponseWrite(id);

  }

  }

  }

  還要去對iis設置

  

  這樣的話偽靜態就可以用了

  C:\WINDOWS\MicrosoftNET\Framework\v\aspnet_isapidll 這是上面的路徑

  浏覽Defaultaspx頁

  ListCategoriesaspx 頁面其實在服務器上面是沒有的它裡面的內容是Defaultaspx的內容因為配置文件裡面設置了


From:http://tw.wingwit.com/Article/program/net/201311/11490.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.