代码之家  ›  专栏  ›  技术社区  ›  Kevin Griffin

响应。使用~path重定向

  •  27
  • Kevin Griffin  · 技术社区  · 17 年前

    我有一个方法,我想将用户重定向回位于Web应用程序根目录下的登录页面。

    我使用以下代码:

    Response.Redirect("~/Login.aspx?ReturnPath=" + Request.Url.ToString());
    

    但这不起作用。我的假设是ASP.NET会自动将URL解析为正确的路径。通常,我会用

    Response.Redirect("../Login.aspx?ReturnPath=" + Request.Url.ToString());
    

    但此代码位于母版页上,可以从任何文件夹级别执行。我如何解决这个问题?

    3 回复  |  直到 7 年前
        1
  •  66
  •   Duncan Smart    13 年前

    ResolveUrl Redirect http://server/ ReturnPath

    Response.Redirect("~/Login.aspx?ReturnPath=" + Server.UrlEncode(Request.Url.ToString()));
    

    Uri.ToString

    Response.Redirect("~/Login.aspx?ReturnPath=" + Server.UrlEncode(Request.Url.AbsoluteUri));
    
        2
  •  0
  •   Pavan k    7 年前

        3
  •  -3
  •   Marshall    17 年前

    Response.Redirect(String.Format("http://{0}/Login.aspx?ReturnPath={1}", Request.ServerVariables["SERVER_NAME"], Request.Url.ToString()));