复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HttpCookie cookie = Request.Cookies["loginInfo"];
if (cookie != null)
{
cb_repwd.Checked = true;
tb_loginName.Text = UIHelper.Decrypt(cookie["loginName"]);
tb_pwd.Attributes.Add("value", UIHelper.Decrypt(cookie["pwd"]));
}
else
{
tb_pwd.Attributes.Add("value", "******");
}
}
}
protected void btn_login_Click(object sender, EventArgs e)
{
if (UIHelper.GetString(Session["Code"]).ToUpper()!=this.tb_code.Text.Trim().ToUpper())
{
oJavaScript.Alert("验证码输入不正确");
return;
}
NetUserService NerService = ContextFactory.GetObject<NetUserService>("NetUserService");
string sql = string.Format("from NetUser where LoginName='{0}'", tb_loginName.Text.Trim());
IList<NetUser> list = NerService.Find(sql);
if (list.Count > 0)
{
if (list[0].Status == 2)
{
oJavaScript.Alert("帐号已停用,请联系管理员");
return;
}
}
if (NerService.Login(tb_loginName.Text.Trim(), oSecurity.GetPwdEncrypt(tb_pwd.Text.Trim())))
{
HttpCookie cookie = Request.Cookies["loginInfo"];
if (cb_repwd.Checked)
{
if (cookie == null)
{
HttpCookie cookielogin = new HttpCookie("loginInfo");
setCookies(cookielogin,7);
}
else
{
if (UIHelper.Decrypt(Request.Cookies["loginInfo"]["loginName"]) != tb_loginName.Text.Trim())
{
setCookies(cookie, 7);
}
}
}
else
{
setCookieExpires(cookie);
}
oJavaScript.Redirect("/");
}
else
{
oJavaScript.Alert( "用户名或密码不正确");
}
}
#region cookie
/// <summary>
/// 设置cookie
/// </summary>
/// <param name="cookielogin">HttpCookie cookielogin</param>
/// <param name="Expires">有效期</param>
private void setCookies(HttpCookie cookielogin, int Expires)
{
cookielogin.Values["loginName"] = UIHelper.Encrypt(tb_loginName.Text.Trim());
cookielogin.Values["pwd"] = UIHelper.Encrypt(tb_pwd.Text.Trim());
cookielogin.Expires = DateTime.Now.AddDays(Expires);
Response.AppendCookie(cookielogin);
}
/// <summary>
/// 设置cookie失效
/// </summary>
/// <param name="cookielogin">HttpCookie cookielogin</param>
private void setCookieExpires(HttpCookie cookielogin)
{
if (cookielogin != null)
{
cookielogin.Expires = DateTime.Now.AddDays(-1); ;
Response.AppendCookie(cookielogin);
}
}
#endregion
设置cookie过期其实就是修改cookie,必须重新向客户端发送cookie
Request.Cookies取cookie, response,cookies添加cookie
虽然简单,但是不太了解的还是很容易出错
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]