如何允许所有用户通过集成身份验证访问网站内的一条路由?
我有一个使用集成安全性的 ASP.Net MVC 应用程序,我需要能够授予对特定路由的开放访问权限。有问题的路线是~/Agreements/Upload
。我已经尝试了一些方法,但到目前为止没有任何效果。
<configuration>
<location path="~/Agreements/Upload">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>
在 IIS 中的“目录安全”>身份验证方法 我只选择了“集成 Windows 身份验证”。现在,这可能是我的问题的一部分(即使 IIS 允许上述 IIS 不允许)。但如果是这种情况,我该如何配置它,以便集成安全性正常工作,但允许未经身份验证的人访问给定的路由?
I have an ASP.Net MVC app using Integrated Security that I need to be able grant open access to a specific route. The route in question is ~/Agreements/Upload
. I have tried a few things and nothing has worked thus far.
<configuration>
<location path="~/Agreements/Upload">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>
In IIS under Directory Security > Authentication Methods I only have "Integrated Windows Authentication" selected. Now, this could be part of my problem (as even though IIS allows the above IIS doesn't). But if that's the case how do I configure it so that Integrated Security works but allows people who aren't authenticated to access the given route?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 ASP.NET MVC 中,不应在 web.config 中使用 location 元素。 Web 表单引擎映射到磁盘上的物理文件,而 MVC 引擎则使用路由。这意味着您可能会无意中允许通过自定义路由访问“受保护的控制器”。
保护 ASP.NET MVC 应用程序的推荐方法是使用 Authorize 属性,如下例所示:
控制器操作是您要保护的内容,而不是路由。 ASP.NET MVC 安全机构 Levi Broderick 对这个问题直言不讳:
In ASP.NET MVC you should not use the location element in the web.config. Whereas the web forms engine mapped to physical files on disk, the MVC engine using routing. This means that you could inadvertently allow access to a "protected controller" through a custom route by accident.
The recommended way of securing ASP.NET MVC applications is through the use of the Authorize attribute, as seen in the example below:
The controller action is what you want to protect and not the route. The ASP.NET MVC Security bod, Levi Broderick is rather vocal about this issue:
您还需要允许 IIS 中的匿名访问,否则只有经过 Windows 身份验证的用户才能访问您站点中的任何位置。默认情况下,您应该拒绝匿名用户的访问。
在您的
部分中,允许匿名用户。You need to allow anonymous access in IIS as well, as otherwise only windows authenticated users will be able to access anywhere in your site. You should deny access by default to anonymous users.
In your
<location>
section, allow anonymous users.