62,046
社区成员
发帖
与我相关
我的任务
分享
cookie.Domain = "huo7.com";
string un = username.Text.Trim();
//判断用户名和密码是否匹配
if (HR_MembersBLL.CheckUser(un, password.Text.Trim()))
{
//建立一个自定义的用户标识存储用户名,用户角色,然后加密后存入cookie
CustomPrincipal cp = new CustomPrincipal();
HR_Members m = HR_MembersBLL.GetMemberByUserName(un);
cp.UserName = un;
List<string> dd = HR_UserInRolesBLL.GetUserInRolesByUsername(un) as List<string>;//权限
cp.Roles = dd.ToArray();
cp.Identity = new GenericIdentity(un);
string s = CustomAuth.ConvertToCompressedString(cp);
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, un, DateTime.Now, DateTime.Now.AddMinutes(60), true, s, FormsAuthentication.FormsCookieName);
string encTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);//将权限等信息保存到cookie
Response.Cookies.Add(authCookie);
……………………
}
else
{
JsAJAX.MessageBox(this, "登录失败,请重试!");
}