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);
    }
}

原文地址:https://www.cnblogs.com/chaoa/p/2386111.html