FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Ticket version
userCode, // Username to be associated with this ticket
DateTime.Now, // Date/time issued
DateTime.Now.AddMinutes(30), // Date/time to expire
true, // "true" for a persistent user cookie (could be a checkbox on form)
UserPrincipal.CreateUserData(staffId), // User-data (the roles from the user record)
FormsAuthentication.FormsCookiePath);
// Hash the cookie for transport over the wire
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // Name of auth cookie
hash); // Hashed ticket
// Add the cookie to the list for outbound response
Response.Cookies.Add(cookie);
Response.Redirect(this.Request.QueryString["ReturnUrl"]);
1, // Ticket version
userCode, // Username to be associated with this ticket
DateTime.Now, // Date/time issued
DateTime.Now.AddMinutes(30), // Date/time to expire
true, // "true" for a persistent user cookie (could be a checkbox on form)
UserPrincipal.CreateUserData(staffId), // User-data (the roles from the user record)
FormsAuthentication.FormsCookiePath);
// Hash the cookie for transport over the wire
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // Name of auth cookie
hash); // Hashed ticket
// Add the cookie to the list for outbound response
Response.Cookies.Add(cookie);
Response.Redirect(this.Request.QueryString["ReturnUrl"]);
解决方案 »
- button点击 事件没有触发
- js 的精度的问题
- 怎么在生成HTML的时候。把图片也生成进去?
- asp.net 分层问题?
- 三个问题:DATAGRID不能分页,ASP。NET中同时显示文本与图片,SQL SERVER无法注册成功
- 紧急求救:关于在aspx文件中包含asp文件的问题?!(在线等待)
- 请问我想做一个即能在webForm 中 使用又能在 WinForm 使用的控件,我该怎么做呢?
- 请问各位你们学习ASP.net都是从哪几步走过来的呢?初学的时候都遇到了什么困难?
- 各位兄弟,你们知道用什么软件可以用来收集自己写过的代码吗?
- 作了一个无限级分类的,在网上看到别人使用下拉列表可以全部将类别显示出来,但是始终做不出来着个效果
- 安装包生成错误,急急急急急急
- 也是一个关于验证的问题?
我门可采用手动添加身份验证票
1.FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket (1,"coffee",DateTime.Now, DateTime.Now.AddMinutes(20), false,UserRoles,"/") ;
2.加密序列化
string HashTicket = FormsAuthentication.Encrypt (Ticket) ;
3.生成cookie
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket) ;4.身份验证票Cookie输出到客户端
Response.Cookies.Add(UserCookie)
5.重定向
Response.Redirect (Context.Request["ReturnUrl"]) ;