asp.net url重寫淺談
URLRewriter.dll----- 是微軟封裝好了的一個URL重寫組件
添加引用----
具體的使用說明請去看
http://msdn.microsoft.com/zh-cn/library/ms972974.aspx#XSLTsection123121120120
比我說得好得多。。
具體使用方法:
首先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個頁面
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>無標(biāo)題頁</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頁面
<h4><a href="javascript:void(0)" onclick="history.go(-1)">返回上一頁</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);
}
}
}
還要去對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基本一樣的。算是簡單化了一點點呵呵。
相關(guān)文章
.net core版 文件上傳/ 支持批量上傳拖拽及預(yù)覽功能(bootstrap fileinput上傳文件)
本篇內(nèi)容主要解決.net core中文件上傳的問題 開發(fā)環(huán)境:ubuntu+vscode.本文給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2017-03-03利用Timer在ASP.NET中實現(xiàn)計劃任務(wù)的方法
利用Timer在ASP.NET中實現(xiàn)計劃任務(wù)的方法...2007-04-04運行asp.net時出現(xiàn) http錯誤404-文件或目錄未找到
問題描述: http錯誤404-文件或目錄未找到的解決方法2009-03-03asp.net使用原生控件實現(xiàn)自定義列導(dǎo)出功能的方法
這篇文章主要給大家介紹了關(guān)于asp.net使用原生控件實現(xiàn)自定義列導(dǎo)出功能的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2022-01-01將選擇的圖片顯示在listview中,并顯示filename,path和type的簡單實例
這篇文章介紹了將選擇的圖片顯示在listview中,并顯示filename,path和type的簡單實例,有需要的朋友可以參考一下2013-10-10MVC使用Memcache+Cookie解決分布式系統(tǒng)共享登錄狀態(tài)學(xué)習(xí)筆記6
這篇文章主要介紹了MVC使用Memcache+Cookie解決分布式系統(tǒng)共享登錄狀態(tài)學(xué)習(xí)筆記,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09asp.net使用Socket.Send發(fā)送信息及Socket.SendFile傳輸文件的方法
這篇文章主要介紹了asp.net使用Socket.Send發(fā)送信息及Socket.SendFile傳輸文件的方法,結(jié)合實例形式分析了asp.net基于socket實現(xiàn)信息與文件傳輸?shù)南嚓P(guān)技巧,需要的朋友可以參考下2016-06-06