Asp.Net在Global.asax中实现URL 的重写

protected void Application_BeginRequest(object sender, EventArgs e)
{
    string url = Request.RawUrl.ToString();
    if (url.ToLower().IndexOf("page/bloglist/"> -1 && url.IndexOf("?"< 0)
    {
        int lastg = url.LastIndexOf("/");
        int lastdot = url.LastIndexOf(".aspx");
        string nurl = String.Format("{0}/blog.aspx?sid={1}", url.Substring(0, lastg), url.Substring(lastg + 1, lastdot - lastg - 1));
        HttpContext.Current.RewritePath(nurl);
    }
}

posted @ 2012-03-09 08:28  Chaoa  阅读(687)  评论(0编辑  收藏  举报