有个 checkBox 如果勾选 则记录用户名 下次登陆就不要再输入咯 ! 我知道用 COOKIES 但.net中我不会搞 ! 大侠帮忙 !
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
- C# code
//-------------将用户和密码保存到cookie里 HttpCookie bcookie = new HttpCookie("UserInfo"); bcookie.Values.Add("User_Name",DBClass.EncryptCookie( tbUserName.Value.Replace(" ", ""))); bcookie.Values.Add("User_Pwd", MD5(TextBox_Pwd.Text)); bcookie.Values.Add("User_Power", DBClass.EncryptCookie("0")); //--------------读取要保存的时间 bcookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(bcookie); HttpCookie cookies = Request.Cookies["UserInfo"]; Label1.Text = DBClass.DecryptCookie(cookies.Values["User_Name"]);
------解决方案--------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
HttpCookie aCookie = Request.Cookies["userInfo"];
if (aCookie != null)
{
Employee el = new Employee();
el.UserID = aCookie.Values["userName"];
if (el.IsOnline())//判断用户是否在线,若在线则删除若不在则直接登陆
{
el.DelOnLine(aCookie.Values["userName"]);
}
User_login(aCookie.Values["userName"], aCookie.Values["password"]);
}
else if (!string.IsNullOrEmpty(Request.QueryString["Name"]) && !string.IsNullOrEmpty(Request.QueryString["Pass"]))
{
User_login(Request.QueryString["Name"], Request.QueryString["Pass"]);
}
}
}
protected void ibtnLogOn_Click(object sender, EventArgs e)
{
if (Ch_Cookie.Checked)
{
HttpCookie cok = Request.Cookies["userInfo"];