【发布时间】:2014-07-19 02:37:27
【问题描述】:
我有一个 MVC 5 应用程序,其 [Authorize] 属性放置在我的控制器类的顶部,我不希望未经授权的用户访问它。我的 Web.config 文件中的设置中有以下内容
<location path="">
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authorization>
<deny users="?"/>
</authorization>
<authentication mode="Forms">
<forms loginUrl="~/Login" timeout="15" />
</authentication>
</system.web>
</location>
当我运行应用程序时,我被重定向到登录页面,但是,如果我知道我想要的控制器/操作的名称,我可以绕过登录页面而无需输入任何凭据,例如与上面相同的控制器我将 [Authorize] 属性放置在类级别。这不应该发生。我意识到这可能与我的 path="" 有关,但我试图拒绝所有访问,直到用户登录并且我尝试了 "*" 和 "~" 但它们不起作用。
【问题讨论】:
标签: asp.net-mvc authorization forms-authentication asp.net-mvc-5