用户登录之asp.net cookie的写入、读取与操作
2020-12-13 04:10
标签:style blog class code c java 页面前面: 要引入的样式: 说明一下,应该是我把这个放在控件Head里,所以引入页面的时候, 用户登录之asp.net cookie的写入、读取与操作,搜素材,soscw.com 用户登录之asp.net cookie的写入、读取与操作 标签:style blog class code c java 原文地址:http://www.cnblogs.com/shy1766IT/p/3731937.html#login { top:0; left: 0; width:580px;height:25px;background:pink;position: relative;float:left}
.button { height: 25px;font-size: 14px; background-color: #0998ff; color: #FFF;padding:3px 12px 5px 12px;border: 0px; vertical-align: middle;margin-left:5px;float:left; }
.button:hover{ background-color: #6699FF;color:#000;cursor:pointer }
.log_input{background-color:#FFF; border:1px solid #d5cfc2;width:130px;height:23px; font-size:14px;vertical-align:middle;float:left}
.log_title{width:90px; display:inline-block; text-align:right;line-height:25px; float:left;color:#FFF;}
#Head_logstate {/*width:200px;*/height:25px;color:#FFF;font-size:14px;line-height: 25px;/*background:blue;*/float:left;position: relative;}
#Head_logstate span { color:#f00;font-weight:800;margin-right:20px}
#Head_logstate a {height:25px;font-size: 14px; background-color: #0998ff; color: #FFF;padding:0 12px 0 12px;border: 0px; vertical-align: middle;float:right}
#Head_logstate a:hover{ background-color: #6699FF;color:#000;cursor:pointer }
logstate这个样式找不到,后来,我就改是
#Head_logstate,才显示正常,而在控件里div的样式还是用的
控件的cs核心代码:
protected string mynames;
protected string myID;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
HttpCookie cookie = Request.Cookies["nickname"];
if (cookie != null) {
mynames = cookie.Value;
GetLogin();
}
}
}
protected void Button1_Click(object sender, EventArgs e) {
string name = t_LogName.Value.Trim();
string pw = t_LogPass.Value.Trim();
if (name.IndexOf("‘") > 0 || name.IndexOf("--") > 0) {
HelperJS.Show(this.Page, "账号(昵称)存在非法字符!");
return;
}
if (name != string.Empty && pw != string.Empty) {
//检查用户名密码
DataTable dt = HelperExecuteSql.Query("select ID,nickname,pw from _user where nickname=‘" + name + "‘ and pw =‘" + pw + "‘").Tables[0];
if (dt.Rows.Count > 0) {
myID = dt.Rows[0]["ID"].ToString();
//Session["nickname"] = name;
//Session["ID"] = Convert.ToInt32(dt.Rows[0][0].ToString());
//uesrName.Text = dt.Rows[0]["nickname"].ToString();
if (Request["ReturnUrl"] == null || Request["ReturnUrl"] == "") {
string nowtime = DateTime.Now.ToString(); //获取当前时间
HttpCookie cookie = new HttpCookie("nickname", HttpUtility.UrlEncode(name));//获取用户的用户名
cookie.Expires = DateTime.Now.AddHours(2);//设置cookie过期时间为2小时后
Response.Cookies.Add(cookie);//将cookie写入客户端
HttpCookie cookie1 = new HttpCookie("nowTime", nowtime);
cookie1.Expires = DateTime.Now.AddHours(2);//设置cookie过期时间为2小时后
Response.Cookies.Add(cookie1);//将cookie1写入客户端
HttpCookie cookie2 = new HttpCookie("ID", myID);//获取用户的ID
Response.Cookies.Add(cookie2);//将cookie2写入客户端
Response.Write(" "); //刷新
}
else {
Server.Transfer(Request["ReturnUrl"]);
}
}
else {
HelperJS.Show(this.Page, "用户名或密码不正确!");
}
}
else {
HelperJS.Show(this.Page, "用户名或密码不能为空!");
}
}
protected void out_click(object sender, EventArgs e) //退出
{
Response.Cookies["nickname"].Expires = DateTime.Now;//cookie将马上过期
login.Visible = true;
logstate.Visible = false;
Response.Write(" "); //刷新
}
文章标题:用户登录之asp.net cookie的写入、读取与操作
文章链接:http://soscw.com/essay/29057.html