form FormsAuthentication.RedirectFromLoginPage form身份验证通过后,只能用FormsAuthentication.RedirectFromLoginP

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

form FormsAuthentication.RedirectFromLoginPage form身份验证通过后,只能用FormsAuthentication.RedirectFromLoginP

  2021-03-17 我要评论
想了解form身份验证通过后,只能用FormsAuthentication.RedirectFromLoginPage的相关内容吗,在本文为您仔细讲解form FormsAuthentication.RedirectFromLoginPage的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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"]) ;

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们