asp.net form 验证 和取值
2012-05-18 16:53
232 查看
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
"ticketName",
DateTime.Now,
DateTime.Now.AddMinutes(60),
false,
"{UserNAme:'sanmao'}"
);
string token = FormsAuthentication.Encrypt(ticket);
HttpCookie userCookie = new HttpCookie(FormsAuthentication.FormsCookieName, token);
Response.Cookies.Add(userCookie);
string url = FormsAuthentication.GetRedirectUrl(UserName, false);//获取来源地址
Response.Redirect(url);
System.Web.HttpContext context = System.Web.HttpContext.Current;
// 取得用户对象
System.Security.Principal.IPrincipal user = context.User;
// 取得用户的角色数组
System.Web.Security.FormsIdentity fi = user.Identity as System.Web.Security.FormsIdentity;
// 取得用户的票据
System.Web.Security.FormsAuthenticationTicket ticket = fi.Ticket;
// 创建用户所拥有的角色数组
string roleString = ticket.UserData;
// 还原为字符串数组
string[] roleArray = { roleString };//roleString.Split(',');
// 自己创建用户对象
System.Security.Principal.GenericPrincipal principal
= new System.Security.Principal.GenericPrincipal(
user.Identity,
roleArray
);
// 让系统使用我们的拥有角色的用户对象
context.User = principal;
Response.Write(tt);
1,
"ticketName",
DateTime.Now,
DateTime.Now.AddMinutes(60),
false,
"{UserNAme:'sanmao'}"
);
string token = FormsAuthentication.Encrypt(ticket);
HttpCookie userCookie = new HttpCookie(FormsAuthentication.FormsCookieName, token);
Response.Cookies.Add(userCookie);
string url = FormsAuthentication.GetRedirectUrl(UserName, false);//获取来源地址
Response.Redirect(url);
System.Web.HttpContext context = System.Web.HttpContext.Current;
// 取得用户对象
System.Security.Principal.IPrincipal user = context.User;
// 取得用户的角色数组
System.Web.Security.FormsIdentity fi = user.Identity as System.Web.Security.FormsIdentity;
// 取得用户的票据
System.Web.Security.FormsAuthenticationTicket ticket = fi.Ticket;
// 创建用户所拥有的角色数组
string roleString = ticket.UserData;
// 还原为字符串数组
string[] roleArray = { roleString };//roleString.Split(',');
// 自己创建用户对象
System.Security.Principal.GenericPrincipal principal
= new System.Security.Principal.GenericPrincipal(
user.Identity,
roleArray
);
// 让系统使用我们的拥有角色的用户对象
context.User = principal;
Response.Write(tt);
相关文章推荐
- Asp.netForm 验证
- ASP.NET在IE10中Form表单身份验证失效问题解决方法
- 使托管在Asp.net中的WCF服务也使用Form验证
- ASP.NET MVC Form验证
- 弄懂ASP.NET Form验证
- ASP.NET Form表单验证(转贴)
- Asp.net中的Form身份验证
- Asp.Net_Form验证跟授权
- ASP.NET中Form验证登录后反复跳转回登录页面的问题
- ASP.net Form验证
- 自己实现 ASP.Net Form 验证
- ASP.NET表单验证之Form
- ASP.NET在IE10,IE11中Form表单身份验证失效问题解决方法
- 关于ASP.NET中FORM验证的写法?
- 关于asp.net的Form验证的一些设置
- Asp.Net 在同一个Form关闭提交时的验证功能。
- ASP.NET中FORM验证中的cookieless属性
- asp.net form 验证方式的使用(转载)
- asp.net中基于Form验证的角色授权验证
- ASP.NET4中不要相信Request.Browser.Cookies,Form验证要用UseCookies