form身份验证通过后,只能用FormsAuthentication.RedirectFromLoginPage
更新时间:2009年03月05日 00:38:18 作者:
form身份验证通过后,只能用FormsAuthentication.RedirectFromLoginPage
直接用Response.Redirect("default.aspx")的话当然验证失败,因为你根本没有建立身份验证票。FormsAuthentication.RedirectFromLoginPage方法,会自动完成很多功能的。如完成生成身份验证票,写回客户端,浏览器重定向等一系列的动作。当然完成这些功能并不是只有FormsAuthentication.RedirectFromLoginPage方法才能办到,相反如果需要带角色信息的验证则只能采用其他办法。
我门可采用手动添加身份验证票
1.
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket (1,"coffee",DateTime.Now, DateTime.Now.AddMinutes(20), false,UserRoles,"/") ;
注:UserRoles不知道就写""
2.加密序列化
string HashTicket = FormsAuthentication.Encrypt (Ticket) ;
3.生成cookie
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket) ;
cookie.Domain = ".jb51.net";
4.身份验证票Cookie输出到客户端
Response.Cookies.Add(UserCookie)
5.重定向
Response.Redirect (Context.Request["ReturnUrl"]) ;
我门可采用手动添加身份验证票
1.
复制代码 代码如下:
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket (1,"coffee",DateTime.Now, DateTime.Now.AddMinutes(20), false,UserRoles,"/") ;
注:UserRoles不知道就写""
2.加密序列化
复制代码 代码如下:
string HashTicket = FormsAuthentication.Encrypt (Ticket) ;
3.生成cookie
复制代码 代码如下:
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket) ;
cookie.Domain = ".jb51.net";
4.身份验证票Cookie输出到客户端
复制代码 代码如下:
Response.Cookies.Add(UserCookie)
5.重定向
复制代码 代码如下:
Response.Redirect (Context.Request["ReturnUrl"]) ;
您可能感兴趣的文章:
- Python使用QQ邮箱发送邮件报错smtplib.SMTPAuthenticationError
- mysql 8.0 错误The server requested authentication method unknown to the client解决方法
- django认证系统 Authentication使用详解
- Java Jedis NOAUTH Authentication required问题解决方法
- 如何解决redis的NOAUTH Authentication required异常
- springboot+Oauth2实现自定义AuthenticationManager和认证path
- HTTP基本认证(Basic Authentication)的JAVA实例代码
- Spring Security如何基于Authentication获取用户信息
相关文章
asp.net Repeater控件的说明及详细介绍及使用方法
Repeater控件是Web 服务器控件中的一个容器控件,它使您可以从页的任何可用数据中创建出自定义列表。2010-04-04国产化之银河麒麟安装.NetCore包管理器方式(步骤详解)
这篇文章主要介绍了国产化之银河麒麟安装.NetCore-包管理器方式,本文给大家分享安装步骤及安装命令,对银河麒麟安装.NetCore相关知识感兴趣的朋友一起看看吧2022-03-03asp.net CheckBoxList各项最小宽度CSS样式(兼容性good)
ASP.NET中,CheckBoxList里的选择都是自动宽度的,属性时没有设置各项宽度的设置,在IE10、遨游4极速模式及兼容模式下均可正确显示最小宽度,此样式除了用于CheckBoxList外,也可用于DIV等2013-04-04详解如何在ASP.NET Core Web API中以三种方式返回数据
这篇文章主要介绍了详解如何在ASP.NET Core Web API中以三种方式返回数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2021-01-01
最新评论