HttpModule Url 重写
1.新建MyModule去实现IHttpModule接口
//当前请求的应用程序的对象的变量
private HttpApplication _application;
//初始化事件
public void Init(HttpApplication context)
{
_application = context;
//加载context执行的事件context_BeginRequest
context.BeginRequest+=new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
//在此对请求的Url重写
//要定义到的路径
string path = "admin/index.aspx";
//获取被请求的路径
string requstPath = _application.Context.Request.RawUrl;
string[] list = requstPath.Split(Convert.ToChar("/"));
if(list[list.Length-1]=="index.aspx")
{
_application.Context.RewritePath(path);
}
}
2.配置文件,定义全局应用该MyModeule
<httpModules>
<add name="MyModule" type="MyModule,App_Code"/>
</httpModules>
主要用于隐藏URL地址或者是伪装URL