asp.net URL重写
Context.RewritePath 方法重写URL
void Application_BeginRequest(object sender, EventArgs e) { string url = Request.AppRelativeCurrentExecutionFilePath; //~/NewsAdmin/NewsList.aspx?pages=2 //~/NewsAdmin/NewsList_2.aspx Match match = Regex.Match(url, @"(~/NewsAdmin/NewsList)_(\d+)(.aspx)"); if (match.Success) { url = match.Groups[1].Value + match.Groups[3].Value + "?pages=" + match.Groups[2].Value; Context.RewritePath(url); } }
BeginRequest事件中,未设置Session会话。
如果要判断Session值,需要在AcquireRequestState事件中校验。