HttpModule
修改HTTP输出
MyModule.cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
///MyModule 的摘要说明
/// </summary>
public class MyModule:IHttpModule
{
public MyModule()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
#region IHttpModule 成员
public void Dispose()
{
}
HttpContext _current = null;
public void Init(HttpApplication context)
{
this._current = context.Context; //Context是应用程序对象的属性,表示上下文对象
context.BeginRequest += new EventHandler(context_BeginRequest);
context.EndRequest += new EventHandler(context_EndRequest);
}
void context_EndRequest(object sender, EventArgs e){
_current.Response.Write("<!--request end -->");
}
void context_BeginRequest(object sender, EventArgs e){
_current.Response.Write("<!--request begin -->");
}
#endregion
}
URL重写
UrlReWrite.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
///UrlReWrite 的摘要说明
/// </summary>
public class UrlReWrite:IHttpModule
{
public UrlReWrite()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
#region IHttpModule 成员
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
HttpRequest re = app.Request;
string path = re.Path;
if (path.Substring(path.LastIndexOf("/") + 1) == "default2.html")
{
string[] strs = path.Split('/');
if (strs.Length != 5)
{
return;
}
else
{
string sid = strs[2];
string sname = strs[3];
app.Context.RewritePath("~/viewperson.aspx?id=" + sid + "&name=" + sname);
}
}
}
#endregion
}