我在点击链接的时候,有三个参数<a href="Order1.aspx?id=<%# Eval("articleid") %>&giftID=<%# Eval("articleid") %>&Sign=<%# Eval("Sign") %>">
我在 A.aspx 页面 判断  
   if (Session["userid"] == null || Session["userid"] == "")
 {   ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('对不起,您还没有登录,不能查询信息!请先登录!');", true);  string redirect = "~/login.aspx?giftID=" + Articleid + "&id=0&returnurl=" + Server.UrlEncodeHttpContext.Current.Request.Url.PathAndQuery);
                    Response.Redirect(redirect);
                    return;
                                   }
我想达到的目的是,登陆之后 跳回这个页面。就是登陆前点击的页面。请教大家 该怎么做呢。

解决方案 »

  1.   

    Response.Redirect("~/login.aspx?ReturnUrl=" + Server.UrlEncode(Request.RawUrl));
      

  2.   


    protected void btnlogin_Click(object sender, EventArgs e)
        {
            string userName = txtUserName.Text;
            string userPass = txtUserPass.Text;
            int userId = BlogLogic.checkLogin(userName, userPass);
            if (userId > 0)
            {
                Session["userId"] = userId;
                Session["userName"] = userName;
                //Response.Redirect("MyFirst.aspx");            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(20), true, "");
                string encryptTicket = FormsAuthentication.Encrypt(ticket);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptTicket);
                Response.Cookies.Add(cookie);//向cookies数组中添加一个cookie
                if (Request.QueryString["ReturnUrl"] == null)
                {
                    Response.Redirect("MyFirst.aspx");//登录成功之后
                }
                else
                {
                    Response.Redirect(Request.QueryString["ReturnUrl"]); //ReturnUrl就是登录之前点击的那个页面,跳回之前的那个页面
                }
            }
            else
            {
                Response.Redirect("Welcome.aspx"); //否则跳会登录页面
            }
        }
      

  3.   

    不管有几个参数,都可以
    在登录前的页面上,使用这样的语句来动态改变将传给登录页的参数 ReturnUrl,该参数表示在登录页(Login.aspx)上处理完毕用户的登录动作之后应该转向的 URL 位置<a href="/login.aspx?ReturnUrl=<%=Server.UrlEncode(Request.RawUrl)%>">登录</a>在 Login.aspx 的代码里,可以获取到这个 ReturnUrl 的值,如果有的话就转向,否则跳到一个默认的位置(如站点的首页)