ASP.NET在web.config中的认证配置
ASP.NET支持在web.config中直接进行访问权限的管理,具体如下,以下是网站根目录下的web.config代码片段
<configuration> <location path="Styles/Site.css"> <system.web> <authorization> <allow users="*"/> </authorization> </system.web> </location> <system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Forms"> <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> </authentication> <authorization> <allow users="maple,maple2"/> <deny users="*"/> </authorization> </configuration>
意为所有未登陆过的或登录用户名不为maple和maple2的访问都会被跳转到登录页面~/Account/Login.aspx;由于CSS文件的特殊性,需要将访问权限开放给所有用户。
更多配置可参考web.config详解和asp.net的登录验证方法 Web.config 的作用范围 拒绝与巧用允许 访问权限配置
标签: DotNet
最新我了搞了个win的vps没事折腾一下。。连基本的都不会。。。
这样配置简单多了,不需要在页面上单独判断了