.net中验证用户安全信息

来源:互联网 发布:php自动实例化 编辑:程序博客网 时间:2024/04/26 02:48
FormsAuthentication里有SetAuthCookie和RedirectFromLoginPage两个方法将用户的登陆信息(标记)记录到Cookie中


而Forms认证方式中的HttpContext.Current.User.Identity.IsAuthenticated;依赖于这个Cookie里的信息判断用户是否登陆。


FormsAuthentication.SignOut用来清除这个Cookie标记


用法如下
FormsAuthentication.SetAuthCookie(userID, createPersistentCookie);
FormsAuthentication.RedirectFromLoginPage(userID, createPersistentCookie);


其中userID可以在HttpContext.Current.User.Identity.Name;或者Page.User.Identifiy.Name;中重新获得


注意:以上是form验证信息  需要在webconfig中 验证方式改为 Forms  <authentication mode="Forms" /> 

0 0
原创粉丝点击