自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

.NET重寫URL方法談

開發(fā) 后端
在這里我們將介紹.NET環(huán)境下的重寫URL方法,希望本文能對大家了解.NET重寫URL有所幫助。

對于.NET重寫URL,也就是Rewriter URL相信大家都不太陌生。在這里我們要介紹的也是.NET重寫URL方法,希望能為大家打開新的思路。

最近小項目要求重寫url找了下資料用到了MS的2個dll,微軟的例子寫得太不明顯了。后來終于改好了。

ActionlessForm.dll------用來處理回發(fā)

URLRewriter.dll----- 是微軟封裝好了的一個URL重寫組件

添加引用----

具體的使用說明請去看

http://msdn.microsoft.com/zh-cn/library/ms972974.aspx#XSLTsection123121120120

比我說得好得多。。

具體使用方法:

首先web.config的配置:

  1. <?xml version="1.0"?> 
  2. <configuration> 
  3.   <configSections> 
  4.     <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,  
  5.  URLRewriter" /> 
  6.   </configSections> 
  7.     <RewriterConfig> 
  8.         <Rules> 
  9.             <RewriterRule> 
  10.                 <LookFor>~/ListCategories\.aspx</LookFor> 
  11.                 <SendTo>~/Default.aspx</SendTo> 
  12.             </RewriterRule> 
  13.             <RewriterRule> 
  14.                 <LookFor>~/(\d+)\.html</LookFor> 
  15.                 <SendTo>~/Cover.aspx?id=$1</SendTo> 
  16.             </RewriterRule> 
  17.         </Rules> 
  18.     </RewriterConfig> 
  19.     <system.web> 
  20.         <httpModules> 
  21.             <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/> 
  22.         </httpModules> 
  23.         <compilation debug="true"/> 
  24. </system.web> 
  25. </configuration> 

主要配置的代碼是這些。其他的根據(jù)自己的需要和.net的版本自行添加。

然后Default.aspx,Cover.aspx,新建2個頁面

Default.aspx:

  1. <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> 
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml"> 
  6. <head runat="server"> 
  7.     <title>無標(biāo)題頁</title> 
  8. </head> 
  9. <body> 
  10.     <form id="form1" runat="server"> 
  11.     <div> 
  12.     <a href="ListCategories.aspx">ListCategories.aspx</a> 
  13.     <a href="30.html">30.html</a> 
  14.     </div> 
  15.     </form> 
  16. </body> 
  17. </html> 

Cover.aspx:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cover.aspx.cs" Inherits="Cover" %> 
  2. <%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %> 
  3.  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml"> 
  7. <head runat="server"> 
  8.     <title>Cover</title> 
  9. </head> 
  10. <body> 
  11.     <skm:form id="form1" runat="server"> 
  12.     <div> 
  13.     Cover頁面  
  14.     <h4><a href="javascript:void(0)" onclick="history.go(-1)">返回上一頁</a></h4> 
  15.         <asp:Button ID="Button1" runat="server" Text="Button" /> 
  16.     </div> 
  17.     </skm:form> 
  18. </body> 
  19. </html> 

Cover.aspx.cs:

  1. using System;  
  2. using System.Collections;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Linq;  
  6. using System.Web;  
  7. using System.Web.Security;  
  8. using System.Web.UI;  
  9. using System.Web.UI.HtmlControls;  
  10. using System.Web.UI.WebControls;  
  11. using System.Web.UI.WebControls.WebParts;  
  12. using System.Xml.Linq;  
  13.  
  14. public partial class Cover : System.Web.UI.Page  
  15. {  
  16.     protected void Page_Load(object sender, EventArgs e)  
  17.     {  
  18.         if (Request.QueryString["id"] == null)  
  19.         {  
  20.             Response.End();  
  21.         }  
  22.         else  
  23.         {  
  24.             int id = Convert.ToInt32(Request.QueryString["id"]);  
  25.             Response.Write(id);  
  26.         }  
  27.     }  

還要去對IIS設(shè)置:

IIS設(shè)置

這樣的話偽靜態(tài)就可以用了

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll ---這是上面的路徑

瀏覽Default.aspx頁

ListCategories.aspx --頁面其實在服務(wù)器上面是沒有的。它里面的內(nèi)容是Default.aspx的內(nèi)容,因為配置文件里面設(shè)置了

寫得有點亂。

本例子是和微軟的重寫url基本一樣的。算是簡單化了一點點呵呵。

原文標(biāo)題:.net重寫url淺談

鏈接:http://www.cnblogs.com/ret00100/archive/2009/10/12/1581778.html

【編輯推薦】

  1. 詳解ASP.NET MVC分頁的實現(xiàn)方法
  2. ASP.NET MVC與WebForm區(qū)別談
  3. ASP.NET MVC應(yīng)用程序執(zhí)行過程分析
  4. ASP.NET MVC分頁控件的實現(xiàn)
  5. 有關(guān)ASP.NET MVC框架的一些基礎(chǔ)知識
責(zé)任編輯:彭凡 來源: 博客園
相關(guān)推薦

2009-07-31 09:39:59

ASP.NET和URL

2009-08-05 14:46:17

ASP.NET url

2009-12-30 14:28:09

ASP.NET Web

2010-01-22 15:56:03

VB.NET獲取當(dāng)前U

2009-01-04 13:27:10

URL RewriteIISASP.NET

2021-03-18 23:38:26

EqualsHashcode方法

2023-08-21 11:09:38

IngressNginxApache

2011-05-20 14:22:11

.NET

2009-09-07 19:03:08

2015-07-08 10:01:55

JavaURL重寫過程實錄

2009-11-13 16:04:54

ADO.NET連接數(shù)據(jù)

2024-07-22 16:26:47

2009-08-05 13:16:43

ASP.NET URL

2009-09-14 15:04:44

2012-07-31 13:28:03

GAE

2009-11-04 13:33:13

ADO.NET Dat

2009-07-31 09:58:20

URL映射ASP.NET

2021-08-13 12:05:15

Goneturl

2009-07-27 17:15:51

URL RewriteASP.NET

2009-08-17 09:30:28

.NET 4.0
點贊
收藏

51CTO技術(shù)棧公眾號