·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> 利用FormsAuthentication.RedirectFromLoginPage进行身份验证

利用FormsAuthentication.RedirectFromLoginPage进行身份验证

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

利用FormsAuthentication.RedirectFromLoginPage进行身份验证

web.config中:

<authentication>节

格式:

<authentication mode="Forms"> //I.Windows: 使用IIS验证方式 II.Forms: 使用基于窗体的验证方式 III.Passport: 采用Passport cookie验证模式 IV.None: 不采用任何验证方式

<forms name=".aspXUSERDEMO" loginUrl="Login.aspx" PRotection="All" timeout="30" defaultUrl="default.aspx"/>

//I.Name: 指定完成身份验证的Http cookie的名称. II.LoginUrl: 如果未通过验证或超时后重定向的页面URL,一般为登录页面,让用户重新登录 III.Protection: 指定 cookie数据的保护方式[a. All表示加密数据,并进行有效性验证两种方式 b. None表示不保护Cookie. c. Encryption表示对Cookie内容进行加密 d. validation表示对Cookie内容进行有效性验证]. IV. TimeOut: 指定Cookie的失效时间. 超时后要重新登录.

</authentication>

<authorization>

<deny users="?"/> //此处如果该为*,则针对所有用户,包过通过验证的用户都起作用

</authorization>

login.aspx中:

FormsAuthentication.RedirectFromLoginPage(userid,false); //重新定位至前一个页面

Response.Redirect("zzz.aspx");

//RedirectFromLoginPage是封装了传登录信息,必须要是 mode="Forms"才能传,Response.Redirect转页。

//得这个值是Page.User.Identity.Name[其中存贮着userid]

//与GetRedirectUrl区别:后者存储defaultUrl="default.aspx"中定义的位置

清除forms验证的办法:

FormsAuthentication.SignOut();

转载自:http://hi.baidu.com/yfqsdie/item/36338cbe7df31ca0ebba9331