Url跳过HttpContext.Current.Request.Url.AbsoluteUri中的第二个查询字符串参数



我有一个类,我继承到所有页面来检查会话是否超时,然后重定向到登录页面,这里是代码

public class WMUserBase:System.Web.UI.Page
{
    public WMUserBase()
    {
    }
    protected override void OnLoad(System.EventArgs e)
    {
        CheckSecurity();
        base.OnLoad(e);
    }
    public virtual void CheckSecurity()
    {
        if (Session["WMuserId"] == null || Session["WMuserId"].ToString() == "")
        {
            Response.Redirect("Login.aspx?ReturnUrl=" + HttpContext.Current.Request.Url.AbsoluteUri);
        }
    }
}

每个页面都继承这个类,如果会话超时,则页面将重定向到我现在使用的登录页面
Response.Redirect("Login.aspx?ReturnUrl=" + HttpContext.Current.Request.Url.AbsoluteUri);但是如果我的querystring有两个参数,例如http://localhost/mala3ibnav2/WeeklyManager/TeamSetup.aspx?Gid=MTQ=&Mid=Mg==在AbsoluteUril&Mid=Mg==有时会被跳过,但并非总是如此
这是登录页面登录按钮点击事件的代码

 if(string.IsNullOrEmpty(ReturnUrl))
                {
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    Response.Redirect(ReturnUrl);
                }

现在,为什么在querystring中跳过第二个参数,以及我应该使用什么来代替HttpContext.Current.Request.Url.AbsoluteUri

您必须对url:进行编码

Response.Redirect("Login.aspx?ReturnUrl=" + HttpUtility.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri));

如果使用表单身份验证,可以将身份验证超时设置为比会话超时少一分钟。然后您不必自己编写代码,因为ASP.NET会在超时后自动将用户重定向到登录页。

最新更新