asp.net url重寫(xiě)淺談
URLRewriter.dll----- 是微軟封裝好了的一個(gè)URL重寫(xiě)組件
添加引用----
具體的使用說(shuō)明請(qǐng)去看
http://msdn.microsoft.com/zh-cn/library/ms972974.aspx#XSLTsection123121120120
比我說(shuō)得好得多。。
具體使用方法:
首先web.config的配置:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,
URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/ListCategories\.aspx</LookFor>
<SendTo>~/Default.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(\d+)\.html</LookFor>
<SendTo>~/Cover.aspx?id=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<system.web>
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
</httpModules>
<compilation debug="true"/>
</system.web>
</configuration>
主要配置的代碼是這些。其他的根據(jù)自己的需要和.net的版本自行添加。
然后Default.aspx,Cover.aspx,新建2個(gè)頁(yè)面
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>無(wú)標(biāo)題頁(yè)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="ListCategories.aspx">ListCategories.aspx</a>
<a href="30.html">30.html</a>
</div>
</form>
</body>
</html>
Cover.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cover.aspx.cs" Inherits="Cover" %>
<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Cover</title>
</head>
<body>
<skm:form id="form1" runat="server">
<div>
Cover頁(yè)面
<h4><a href="javascript:void(0)" onclick="history.go(-1)">返回上一頁(yè)</a></h4>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</skm:form>
</body>
</html>
Cover.aspx.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Cover : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] == null)
{
Response.End();
}
else
{
int id = Convert.ToInt32(Request.QueryString["id"]);
Response.Write(id);
}
}
}
還要去對(duì)iis設(shè)置:

這樣的話偽靜態(tài)就可以用了
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll ---這是上面的路徑
瀏覽Default.aspx頁(yè)
ListCategories.aspx --頁(yè)面其實(shí)在服務(wù)器上面是沒(méi)有的。它里面的內(nèi)容是Default.aspx的內(nèi)容,因?yàn)榕渲梦募锩嬖O(shè)置了
寫(xiě)得有點(diǎn)亂。
本例子是和微軟的重寫(xiě)url基本一樣的。算是簡(jiǎn)單化了一點(diǎn)點(diǎn)呵呵。
- asp.net不用設(shè)置iis實(shí)現(xiàn)url重寫(xiě) 類似偽靜態(tài)路由
- ASP.NET中獲取URL重寫(xiě)前的原始地址詳解
- URL重寫(xiě)及干掉ASP.NET試圖狀態(tài)的實(shí)現(xiàn)方法
- asp.net URL重寫(xiě)簡(jiǎn)化版 速學(xué)URL重寫(xiě)
- 一個(gè)完整的ASP.NET 2.0 URL重寫(xiě)方案[翻譯]
- asp.net下實(shí)現(xiàn)URL重寫(xiě)技術(shù)的代碼
- asp.net 2.0 中的URL重寫(xiě)以及urlMappings問(wèn)題
- asp.net下用url重寫(xiě)URLReWriter實(shí)現(xiàn)任意二級(jí)域名的方法
- Asp.Net URL重寫(xiě)的具體實(shí)現(xiàn)
相關(guān)文章
C# FTP,GetResponse(),遠(yuǎn)程服務(wù)器返回錯(cuò)誤
C# FTP,GetResponse(),遠(yuǎn)程服務(wù)器返回錯(cuò)誤:(550) 文件不可用(例如,未找到文件,無(wú)法訪問(wèn)文件)2009-06-06
.NET?6開(kāi)發(fā)TodoList應(yīng)用之請(qǐng)求日志組件HttpLogging介紹
這篇文章介紹了.NET?6開(kāi)發(fā)TodoList應(yīng)用之請(qǐng)求日志組件HttpLogging,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01
asp.net?Core中同名服務(wù)注冊(cè)的實(shí)現(xiàn)代碼
Asp.Net?Core中自帶了容器,同時(shí)也可以使用AutoFac替換掉默認(rèn)的容器,以下為兩種方式同名服務(wù)的注冊(cè)實(shí)現(xiàn),對(duì)asp.net?Core服務(wù)注冊(cè)的實(shí)現(xiàn)代碼感興趣的朋友一起看看吧2022-03-03
ASP.NET Core使用AutoMapper實(shí)現(xiàn)實(shí)體映射
本文詳細(xì)講解了ASP.NET Core使用AutoMapper實(shí)現(xiàn)實(shí)體映射的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03
ASP.NET.4.5.1+MVC5.0設(shè)置系統(tǒng)角色與權(quán)限(一)
這篇文章主要介紹了ASP.NET.4.5.1+MVC5.0設(shè)置系統(tǒng)角色與權(quán)限的部分內(nèi)容,后續(xù)我們將繼續(xù)討論這個(gè)話題,希望小伙伴們喜歡。2015-01-01
asp.net(C#)跨域及跨域?qū)慍ookie問(wèn)題
在網(wǎng)站www.A.com下通過(guò)iframe或ajax調(diào)用www.B.com下的內(nèi)容時(shí),默認(rèn)情況下IE會(huì)阻止www.B.com寫(xiě)任何Cookie2011-10-10

