使用cookie 比如HttpCookie myCookie = new HttpCookie("myTestCookies"); // Set the cookie value. myCookie.Values.Add("UserID","A6CA9DD9-F116-4071-BBFE-32C45DF13B5F");
// Set the cookie expiration date. myCookie.Expires = DateTime.Now.AddHours(1); // Set the cookie Domain myCookie.Domain = "csdn.net"; //这里根据你的网站域名或IP // Add the cookie. Response.Cookies.Add(myCookie);
hertcloud(·£孙子兵法£·) ( ) 信誉:100 Blog 2007-04-03 09:18:51 得分: 0
使用cookie 比如HttpCookie myCookie = new HttpCookie("myTestCookies"); // Set the cookie value. myCookie.Values.Add("UserID","A6CA9DD9-F116-4071-BBFE-32C45DF13B5F");
// Set the cookie expiration date. myCookie.Expires = DateTime.Now.AddHours(1); // Set the cookie Domain myCookie.Domain = "csdn.net"; //这里根据你的网站域名或IP // Add the cookie. Response.Cookies.Add(myCookie);
使用cookie 比如HttpCookie myCookie = new HttpCookie("myTestCookies"); // Set the cookie value. myCookie.Values.Add("UserID","A6CA9DD9-F116-4071-BBFE-32C45DF13B5F");
// Set the cookie expiration date. myCookie.Expires = DateTime.Now.AddHours(1); // Set the cookie Domain myCookie.Domain = "csdn.net"; //这里根据你的网站域名或IP // Add the cookie. Response.Cookies.Add(myCookie);--------------------------------------------------------------------- 几乎95%以上的网站用户登录使用进程内Cookie,你是不是想用户离开后一小时内登陆状态还不消失?对网吧用户、公共计算机,这种行为……
在form验证,登录时这么写: if (Membership.ValidateUser(userName, psw)) //在这里验证用户
} else this.Login1.FailureText = "Login failed. Please check your user name and password and try again."; //在别的页面取用户名这么写: string userID = HttpContext.Current.User.Identity.Name;
cookie!Dim UserRoles As String = UserToRoles(reader("M_LEVEL")) '建立身份验证票对象 Dim Ticket As New FormsAuthenticationTicket(1, UserName.Text, DateTime.Now, DateTime.Now.AddMinutes(30), False, UserRoles, "/") '加密序列化验证票为字符串 Dim HashTicket As String = FormsAuthentication.Encrypt(Ticket) '生成Cookie Dim UserCookie As New HttpCookie(FormsAuthentication.FormsCookieName, HashTicket) '输出Cookie Context.Response.Cookies.Add(UserCookie)
第一:csdn的登陆怎么实现的?
第二:用数据库登陆,怎么在每个操作页面判断是哪个用户在操作?不还是要用Session?>
用session没有必要,session过期问题始终是难以从根本上解决的一个问题,还是cookie来得方便,保存在客户端也不会增加服务器开销
myCookie.Values.Add("UserID","A6CA9DD9-F116-4071-BBFE-32C45DF13B5F");
// Set the cookie expiration date.
myCookie.Expires = DateTime.Now.AddHours(1);
// Set the cookie Domain
myCookie.Domain = "csdn.net"; //这里根据你的网站域名或IP // Add the cookie.
Response.Cookies.Add(myCookie);
这样,每次session失效后就把cookie中的值重新读入session中,若cookie也过期了,那就重新登录吧……
使用cookie 比如HttpCookie myCookie = new HttpCookie("myTestCookies"); // Set the cookie value.
myCookie.Values.Add("UserID","A6CA9DD9-F116-4071-BBFE-32C45DF13B5F");
// Set the cookie expiration date.
myCookie.Expires = DateTime.Now.AddHours(1);
// Set the cookie Domain
myCookie.Domain = "csdn.net"; //这里根据你的网站域名或IP // Add the cookie.
Response.Cookies.Add(myCookie);
-----------------
这个可以记录登录的用户!
请问ustbwuyi()和hertcloud:然后怎么在其他页面知道是哪个用户在操作
!
这个用户在以后所有页面我都会用到!?
这样,每次session失效后就把cookie中的值重新读入session中,若cookie也过期了,那就重新登录吧……
------------
登录后 记录其用户名,密码
然后进入主程序 页面!那个用户名和密码 怎么传递?
myCookie.Values.Add("UserID","A6CA9DD9-F116-4071-BBFE-32C45DF13B5F");
// Set the cookie expiration date.
myCookie.Expires = DateTime.Now.AddHours(1);
// Set the cookie Domain
myCookie.Domain = "csdn.net"; //这里根据你的网站域名或IP // Add the cookie.
Response.Cookies.Add(myCookie);---------------------------------------------------------------------
几乎95%以上的网站用户登录使用进程内Cookie,你是不是想用户离开后一小时内登陆状态还不消失?对网吧用户、公共计算机,这种行为……
if (Membership.ValidateUser(userName, psw)) //在这里验证用户
FormsAuthentication.RedirectFromLoginPage(userName, this.Login1.RememberMeSet);
}
else
this.Login1.FailureText = "Login failed. Please check your user name and password and try again.";
//在别的页面取用户名这么写:
string userID = HttpContext.Current.User.Identity.Name;
'建立身份验证票对象
Dim Ticket As New FormsAuthenticationTicket(1, UserName.Text, DateTime.Now, DateTime.Now.AddMinutes(30), False, UserRoles, "/")
'加密序列化验证票为字符串
Dim HashTicket As String = FormsAuthentication.Encrypt(Ticket)
'生成Cookie
Dim UserCookie As New HttpCookie(FormsAuthentication.FormsCookieName, HashTicket)
'输出Cookie
Context.Response.Cookies.Add(UserCookie)
如果是对安全性要求比较高的场合,还是每次都要登录吧,比如淘宝,会用coockie记着用户名,但是要进行操作就必选先登录
---------
那要怎么处理才能做到要他什么时候退出就退出\\?