1----------------------------在全局配置文件中写url重写
//命名规则 一定要以 Application_ 作为开头 url 重写
protected void Application_BeginRequest(object sender, EventArgs e)
{
System.Web.HttpApplication app = sender as HttpApplication;
fackProcess(app);
}
void fackProcess(HttpApplication app)
{
//
HttpContext context = app.Context;
//获取当前的静态url /Student/Detaiel/1
string statcinrul = context.Request.RawUrl;
//解析url
string[] strpath = statcinrul.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
//判断url
if (strpath[0] == "student") // /student
{
if (strpath[1] == "list") // /student/list
{
}
else if (strpath[1]=="details")// student/details
{
// dtudent/details/1
if (strpath.Length == 3 && !string.IsNullOrEmpty(strpath[2]))
{
//符合 重写url
context.RewritePath("/2.aspx?id=" + strpath[2]);
}
}
}
}
2-------------------------------------------------