HttpContext.RewritePath

 定义:使用给定路径重写 URL。就是可以跳转到指定的URL。

也可以做为伪静态的跳转。具体如下。

他的重载

①新建一个页面,放两个链接到另一个页面,注意给的链接

②在 global.asax 文件中 (需要在访问页面之前执行的事件)

 protected void Application_BeginRequest(Object sender, EventArgs e)
        {
            string originalPath = HttpContext.Current.Request.Path.ToLower();//虚拟路径
            if (originalPath.Contains("/page1"))
            {
                HttpContext.Current.RewritePath(originalPath.Replace("/page1", "/WebForm2.aspx?page=1"));
            }
            if (originalPath.Contains("/page2"))
            {
                //第二个参数为资源的附加路径信息
                HttpContext.Current.RewritePath(originalPath.Replace("/page2", "/WebForm2.aspx"), "pathinfo", "page=2");
            }
        }

③我们的WebForm2.aspx页面

显示效果如下

 这也可以看做为 伪静态。 这篇文章也是打的基础。

原文地址:https://www.cnblogs.com/Sea1ee/p/7495280.html