ASP.NET(c#) 中通过配置配置authentication 来验证控制 Login 登录
2014-12-30 16:33
537 查看
本文讲述如何在web.cofig里通过配置authentication节点来控制权限登录。其实关键点就是配置Web.config 文件
cookieless:用户登录后的cookieName(可选)
defaultUrl:正确登录之后,在没有指向页的时候,弄人跳转的页面(可选)
authorization节点功能是拒绝匿名用户访问该文件夹目录下所有文件功能
到目前为止,除了Default.aspx和progressbar.aspx页面,你访问其他的页面,都会自动跳转到Default.aspx登陆页面,要求你先登录。
如果有其它异常问题,web.config中通过外置location 元素来锁定配置设置
其它可参考我之前的文章: http://blog.csdn.net/jintougao/article/details/9281275
一,配置Web.config
首先在 Web.config <authentication> 里将身份验证模式更改为Forms(窗体)。具体代码如下<system.web> <!--拒绝匿名用户访问--> <authentication mode="Forms"> <forms loginUrl="Default.aspx" defaultUrl="Admin.aspx" name=".ASPXFORMSAUTH"> </forms> </authentication> <authorization> <deny users="?"/> <!--<allow users = "*" />--> </authorization> </system.web> <location path="progressbar.aspx"> <system.web> <authorization> <allow users="?" /> </authorization> </system.web> </location>loginUrl:用户没有登录,跳转到的登录页面
cookieless:用户登录后的cookieName(可选)
defaultUrl:正确登录之后,在没有指向页的时候,弄人跳转的页面(可选)
authorization节点功能是拒绝匿名用户访问该文件夹目录下所有文件功能
到目前为止,除了Default.aspx和progressbar.aspx页面,你访问其他的页面,都会自动跳转到Default.aspx登陆页面,要求你先登录。
如果有其它异常问题,web.config中通过外置location 元素来锁定配置设置
二,页面后台的代码应用
protected void btnLogIn_Click(object sender, EventArgs e) { string userName = "", password = ""; using (StreamReader sr = File.OpenText("D:\\Temp\\user info.txt")) { string input = null; while ((input = sr.ReadLine()) != null) { if (input == userName) { input = sr.ReadLine(); if (input == password) { //other else options } } } } } protected void User_Logout() { Session.Abandon(); //删除用户票据 FormsAuthentication.SignOut(); //重新定向到登陆页面 FormsAuthentication.RedirectToLoginPage(); }其中User_Logout()方法是注销登录用
其它可参考我之前的文章: http://blog.csdn.net/jintougao/article/details/9281275
相关文章推荐
- 傻瓜教程:asp.net(c#) 如何配置authentication,完成基于表单的身份验证
- 如何在ASP.NET中使用验证通过的Windows Live ID用户登录网站
- asp.net 如何配置authentication,完成基于表单的身份验证
- Asp.Net Form验证不通过,重复登录
- Asp.net的登录验证方法Web.config访问权限配置
- ASP.NET&C#登录验证
- asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket
- 通过machineKey配置解决asp.net验证视图状态MAC失败的问题
- 如何在ASP.NET中使用验证通过的Windows Live ID用户登录网站
- 转---asp.net 验证的问题:authentication,解释以及如果要匿名登录一些网页需要如何操作等。
- ASP.NET jQuery 实例11 通过使用jQuery validation插件简单实现用户登录页面验证功能
- C# asp.net 抓取需要登录的网页内容 抓取asp.net登录验证的网站
- asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket
- Asp.net的登录验证方法Web.config访问权限配置
- WEBCONFIG配置ACCESS数据库(C#) ASP.NET+ACCESS登陆验证
- ASP.NET Core中实现用户登录验证的最低配置示例代码
- asp.net的登录验证方法 Web.config 的作用范围 配置
- asp.net 登陆验证 Form表单验证的3种方式 FormsAuthentication.SetAuthCookie;FormsAuthentication.RedirectFromLoginPage;FormsAuthenticationTicket
- ASP.NET Core 实现用户登录验证的最低配置
- ASP.net中Security.FormsAuthentication验证用户的状态(匿名|已登录)