我通过以下代码写入COOKIES记录登陆信息.可是我还想同时记录其它的登陆信息,比如登陆者的城市地区,等也写入到这个COOKIES中,如何实现?
string userName = username1.Text;
string password = password1.Text;
if ((Membership.ValidateUser(userName, password))) {
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddSeconds(600), CheckBox1.Checked, "roles", FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(authCookie);
Response.Redirect("../7index/member.aspx");
} else {
lblResults.Text = "登陆错误!请重新输入用户名和密码再试!";
if ((!(Membership.GetUser(userName) == null))) {
if ((Membership.GetUser(userName).IsLockedOut == true)) {
lblResults.Text = lblResults.Text + " 您的用户名被锁定,请与管理人员联系!";
}
}
}当这些都写入后,又如何可以修改这些COOKIES呢?比如当登陆者在编辑自己的个人信息时,要求把自己登陆时的COOKIES也要同步修改.如何可以实现.谢谢.
string userName = username1.Text;
string password = password1.Text;
if ((Membership.ValidateUser(userName, password))) {
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddSeconds(600), CheckBox1.Checked, "roles", FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(authCookie);
Response.Redirect("../7index/member.aspx");
} else {
lblResults.Text = "登陆错误!请重新输入用户名和密码再试!";
if ((!(Membership.GetUser(userName) == null))) {
if ((Membership.GetUser(userName).IsLockedOut == true)) {
lblResults.Text = lblResults.Text + " 您的用户名被锁定,请与管理人员联系!";
}
}
}当这些都写入后,又如何可以修改这些COOKIES呢?比如当登陆者在编辑自己的个人信息时,要求把自己登陆时的COOKIES也要同步修改.如何可以实现.谢谢.
不过你可以在建一个Cookie把你要新添的数据写进Cookie集合中
如:HttpCookie cityCookie = new HttpCookie("city", "baijing");
Response.Cookies.Add(cityCookie);
第2个问题 你可以把以前的Cookie删除了在重新写一个Cookie
如:HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName,"");
Response.Cookies.Add(authCookie);
HttpCookie cityCookie = new HttpCookie("city", "");
Response.Cookies.Add(cityCookie);
//调用你写Cookie的方法
比如:AddCookie();
Response.Cookies.Add(authCookie);
一样,加一个
HttpCookie addCookie = new HttpCookie("Address","sdf");
Response.Cookies.Add(addCookie );
应该就可以了。。要修改的时候修改取出来修改不就可以了?
Response.Cookies["Address"].Value = "xxx";