就是那个登陆时选的保存一天保存一个月保存一年那个
希望能说的细一点

解决方案 »

  1.   

       protected void Denglu_Click(object sender, ImageClickEventArgs e)
        {
          
            string UserName = this.username.Text.Trim();
            string passWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.userpass.Text.Trim(), "MD5");         //查询用户名和密码是否和数据库中的相匹配
            DataTable dt = new DataTable();
            string sql = "select username,password,uid from bbs_users where username='"+UserName+"' and password='"+passWord+"'";
            sqls.Fill_DT(sql,dt);
            sqls.ConClose();        if (dt.Rows.Count > 0)
            {
               HttpCookie cookies;//将用户名和密码写入Cookies                cookies = new HttpCookie("UserCookies");
                    cookies.Values["User_Name"] = dt.Rows[0]["username"].ToString();
                    cookies.Values["User_Pwd"] = dt.Rows[0]["password"].ToString();
                    cookies.Values["User_Uid"] = dt.Rows[0]["uid"].ToString();
                    Response.AppendCookie(cookies);
                    cookies.Expires = System.DateTime.Now.AddDays(1);//设置过期时间是7天   
                     Response.Redirect("e8ecom/admin/My_Edit_Data.aspx");
            }
            else
            {
                this.Response.Write("<script>alert('登陆失败!');</script>");
                return;
            }
        }
      

  2.   

    取COOKies HttpCookie myCookie = Request.Cookies["UserCookies"];
    //这里的UserCookies必须和保存的时候那个名字一样
                if (myCookie != null)
                {
                    uid = int.Parse(myCookie["User_Uid"].ToString());
                    sqls.Fill_DT("select itemno from dbo.bbs_Users where uid ='"+uid+"'",dt);
                    if(dt.Rows.Count>0)
                    {
                        this.HLHref.NavigateUrl = "~/e8ecom/Space/MyRecord.aspx?space=" + dt.Rows[0]["itemno"].ToString() + "";
                      }
                    sqls.ConClose();
                }
                else
                {
                    this.Response.Write("<script>alert('您没有登陆');</script>");
                    this.Response.Redirect("../../Login.aspx");
                }