IIS / ASP.NET MVC:特定文件夹上的动态IP地址限制

时间:2013-11-15 00:10:36

标签: c# asp.net asp.net-mvc asp.net-mvc-4 iis

由于它的工作原理,使用WebForms这一点很简单,但是我看不到使用MVC这样做的逻辑方法。 我有一部分应用程序(公共API),我想在其上应用特定的动态IP限制(所以我需要一个仅适用于应用程序某些部分的Web.config文件)。 在WebForms中,我只是创建一个文件夹并在其中放入一个带有相关限制的Web.config文件。 有没有办法用MVC做到这一点?

1 个答案:

答案 0 :(得分:2)

位置元素仍然可以在MVC中用于将配置(如IP限制)应用于MVC应用程序的某些部分:

<location path="secret/api">
  <system.webServer>
    <security>
      <ipSecurity allowUnlisted="false">
        <clear/>
        <add ipAddress="127.0.0.1"/>
      </ipSecurity>
    </security>
  </system.webServer>
</location>