你的位置:首页 > 软件开发 > ASP.net > asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket

asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket

发布时间:2015-05-18 16:00:19
我们在登陆成功后,使用下面的3种方法,都是同一个目的:创建身份验证票并将其附加到 Cookie,当我们用Forms认证方式的时候,可以使用HttpContext.Current.User.Identity.IsAuthenticated (或者也可以用 Request.Is ...

asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket

我们在登陆成功后,使用下面的3种方法,都是同一个目的:创建身份验证票并将其附加到 Cookie,

当我们用Forms认证方式的时候,可以使用HttpContext.Current.User.Identity.IsAuthenticated  (或者也可以用 Request.IsAuthenticated ,这个实际上也是调用的是User.Identity.IsAuthenticated来验证)来判断是否登陆;而这个判断就是依赖于这个Cookie里的信息判断用户是否登陆。 

 

【System.Web.Security.FormsAuthentication.SetAuthCookie("fish", false);】后,Asp.net做了些什么, 回答这个问题其实很简单:自己用Reflector.exe去看一下Asp.net的实现吧。 

 ////创建身份验证票  FormsAuthenticationTicket AuTicket =new FormsAuthenticationTicket( 1, UserInfo.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), false, Request.UserHostAddress); ////将票据加密 get='_blank'>string authTicket = FormsAuthentication.Encrypt(AuTicket); ////将加密后的票据保存为cookie HttpCookie coo =new HttpCookie(FormsAuthentication.FormsCookieName, authTicket); coo.Secure =false; coo.Expires = AuTicket.Expiration; coo.Path = FormsAuthentication.FormsCookiePath; ////加入新cookie Response.Cookies.Add(coo);
asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket

 

 

3:FormsAuthentication.RedirectFromLoginPage

演示:

FormsAuthentication.RedirectFromLoginPage(UserInfo.UserName, false);

原标题:asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket

关键词:ASP.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。