62,046
社区成员
发帖
与我相关
我的任务
分享
//SetLoginCookie方法
public static void SetLoginCookie(AdminUserVO u, string roles)
{
//建立身份验证票对象
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket (1,u.Uname, DateTime.Now, DateTime.Now.AddMinutes(30), false,roles,"/");
//加密序列化验证票为字符串
string hashTicket = FormsAuthentication.Encrypt (ticket) ;
HttpCookie userCookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashTicket);
HttpContext.Current.Response.Cookies.Add(userCookie);
}
public static void RedirectFromLoginPage( string userName, bool createPersistentCookie, string strCookiePath );
<system.web>
<authentication mode="Forms" >
<forms name=".yaoCookies" loginUrl="/duan/Manage/login.aspx" protection="All"
timeout="需要的时间" path="/" />
</authentication>
</system.web>