asp.net-mvc – 如何锁定ASP.NET MVC中的路径?

我第一次使用MVC 4来查看与MVC 3相比更改/添加/ etc的内容.

首先,我创建了一个空白的MVC 4 Web应用程序,并从头开始构建.

我注意到的第一件事是MVC 4中不同的事实是,以下web.config设置对网页的可访问性没有影响:

<configuration>
    <location path="">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
    </location>
    .....
</configuration>

回到MVC 3,上述授权设置将拒绝所有匿名用户访问该站点内的任何内容.但是,如果将相同的设置添加到MVC4 Web.config文件中,匿名者可以自由选择他/他选择的URL.

在MVC 4中需要做什么来锁定所有的路径,就像我在MVC 3中一样?

解决方法

看看 Securing your ASP.NET MVC 4 App and the new AllowAnonymous Attribute.

You cannot use routing or web.config files to secure your MVC application (Any Version). The only supported way to secure your MVC application is to apply the Authorize attribute…

Quote

MVC uses routes and does not map URLs to physical file locations like WebForms,PHP and Traditional web servers. Therefore using web.config will definitely open a security hole in your site.

The product team will have a communication if this changes in the future,but for now it is without exception the rule.

例子:

认的ASP.Net MVC项目(Internet / Intranet)开始.

编辑web.config添加

<location path="Home">
  <system.web>
    <authorization>
      <deny users="*">
    </authorization>
  </system.web>
</location>

运行该项目,认情况下,您将使用认路由/主页/索引,并看到内容,只需绕过web.config,而不更改认模板.为什么?因为ASP.Net管道正在将请求的URL与web.config中指定的位置进行比较.然而,在授权事件在流水线中执行路由(认路由或自定义路由)并允许访问所谓的限制区域之后.

另外,任何MVC重定向()也将绕过授权管道事件之后的路由再次发出相同的安全措施.

我不认为任何人都应该接受职业安全.第一次做到正确,不要懒惰,并使用不是专门用于特定技术的东西.

相关文章

ASP.NET与IIS是紧密联系的,由于IIS6.0与IIS7.0的工作方式的...
在之前的ASP.NET是如何在IIS下工作的这篇文章中介绍了ASP.NE...
这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...