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事件中校验。

posted @ 2014-11-14 06:11  hg一如既往  阅读(206)  评论(0编辑  收藏  举报