请教各位一个问题
   CSDN在用户登陆后是怎么记载最后访问页面的 地址,然后再两秒后自动跳回去的 呀
能给代码吗

解决方案 »

  1.   

    登录时记地址,settimeout(2000)
      

  2.   

    为了方便用户的操作,我们希望用户在登录成功后可以跳转到刚才访问过的页面,为此我们可以在首次加载Login.aspx页面时使用ViewState来存储用户访问过的前一页面的Url,并在登录成功后判断此ViewState的内容来决定跳转的页面
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.UrlReferrer != null)
                ViewState["ReferrerUrl"] = Request.UrlReferrer.ToString();
        }
    }protected void btnLogin_Click(object sender, EventArgs e)
    {
            //做你要做的是事
             Session["UserName"] = txtUserName.Text.Trim();
            if (ViewState["ReferrerUrl"] != null)
                Response.Redirect(ViewState["ReferrerUrl"].ToString());
            else
                Response.Redirect("default.aspx");
    }
      

  3.   

    隔5秒跳转的        protected void btnLogin_Click(object sender, EventArgs e)
            {
            //做你要做的是事
                    Session["UserName"] = txtUserName.Text.Trim();
                    if (ViewState["ReferrerUrl"] != null)
                        Response.Redirect(ViewState["ReferrerUrl"].ToString());
                    else
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/JavaScript'>var t = 5;function countDown(){document.getElementById('lblMessage').innerText = '登录成功!' + t + '秒钟自动跳转到主页...';t--;if(t == 0) location.href='default.aspx';setTimeout(countDown,1000);} countDown();</script>");
                }
            }