在我的web.config我有这样的:Asp.net Forms身份验证
<system.web>
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All" path="/" timeout="30"/>
</authentication>
<sessionState timeout="20" />
</system.web>
<location path="admin">
<system.web>
<authorization>
<deny users="*"/>
<allow users="admin"/>
</authorization>
</system.web>
</location>
我有两个问题:
在我的管理路径我想只有管理员用户访问,但我找不到办法做到这一点。我怎样才能让只有管理员用户有权限访问?
即使我尝试使用cookie,用户总是会注销,因此他不应该注销。在我的login.aspx我有folloing代码,当用户是有效的:
FormsAuthentication.RedirectFromLoginPage(user, CheckBoxPersistCookie.Checked);
我怎样才能使保持登录用户?
嗯,这是很容易,但我只是认为这将是更多的逻辑,你首先否认所有,然后通过添加管理员覆盖之后? :-) – Martin 2009-11-30 13:48:17
在ASP.NET中,授权规则按优先级排列。 – richeym 2009-11-30 13:49:42
是的,那个人也让我愚弄了一下。 .NET在看到下一行之前会看到拒绝*并踢人。 – 2009-11-30 14:25:38