注:需要在该类库中添加system.web引用public class MyUrlWriter:IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler (context_BeginRequest);
}
protected void context_BeginRequest( object sender, EventArgs e)
{
HttpApplication application = sender as HttpApplication ;
HttpContext context = application.Context; //上下文
string url = context.Request.Url.LocalPath; //获得请求URL
Regex articleRegex = new Regex ("/index.html" ); //定义规则
if (articleRegex.IsMatch(url))
{
string paramStr = url.Substring(url.LastIndexOf('/' ) + 1);
context.RewritePath( "/Article.aspx?id=" + paramStr);
}
else
{
context.RewritePath( "/Default.aspx" );
}
}
public void Dispose() { }
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></tit