asp.net FormsAuthentication 认证
2009-05-21 17:25
246 查看
方法一,创建身份票据写cookie
//创建身份验证票
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, "userInfo.UserName", DateTime.Now, DateTime.Now.AddMinutes(20), false, "roles");
//创建身份验证票的加密字符串
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
//将加密字符串存储在 HttpCookie 对象中
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
//将此 cookie 添加到返回给用户浏览器的 cookie 集合中
Response.Cookies.Add(authCookie);
//将用户重定向到默认页
Response.Redirect("~/Default.aspx");
方法二,直接使用系统FormsAuthentication类自动创建身份票据写cookie
FormsAuthentication.RedirectFromLoginPage(username, true);
//按你设定的名字写入cookie.
方法三,使用登陆控件asp:Login不用写代码。
//创建身份验证票
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, "userInfo.UserName", DateTime.Now, DateTime.Now.AddMinutes(20), false, "roles");
//创建身份验证票的加密字符串
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
//将加密字符串存储在 HttpCookie 对象中
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
//将此 cookie 添加到返回给用户浏览器的 cookie 集合中
Response.Cookies.Add(authCookie);
//将用户重定向到默认页
Response.Redirect("~/Default.aspx");
方法二,直接使用系统FormsAuthentication类自动创建身份票据写cookie
FormsAuthentication.RedirectFromLoginPage(username, true);
//按你设定的名字写入cookie.
方法三,使用登陆控件asp:Login不用写代码。
相关文章推荐
- 一个简单的ASP.NET Forms 身份认证的实例方法
- Asp.NET FormsAuthentication
- ASP.NET Forms 身份认证
- 转贴[ASP.NET]基于Forms认证的WebService应用
- ASP.Net 身份验证方法 基本的Forms认证步骤 [转]
- asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket
- ASP.NET Forms身份认证
- 细说ASP.NET Forms身份认证
- Active Directory Authentication in ASP.NET MVC 5 with Forms Authentication and Group-Based Authorization
- 一个简单的ASP.NET Forms 身份认证
- ASP.Net 身份验证方法 基于角色的Forms认证步骤 [转]
- 一个简单的ASP.NET Forms 身份认证(转)
- 一个简单的ASP.NET Forms 身份认证
- ASP.NET Forms身份认证
- ASP.NET 2.0: Forms Authentication Across domains
- ASP.NET Forms身份认证
- ASP.NET MVC 身份认证之Forms认证
- asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket
- ASP.NET Session and Forms Authentication and Session Fixation
- Asp.net forms认证注意事项