将不同的IP指向IIS7上的不同页面

Guy*_*Guy 9 iis-7 web-config ip-address asp.net-routing

使用IIS7,当我将外部IP地址定向到"维护站点"页面时,如何将内部专用网络 IP地址定向到我的网站?

到目前为止,在IIS7上我发现IIS中的部分名为"IPv4地址和域限制",我可以将3个内部范围添加为允许范围.这似乎很容易.现在,我如何将所有其他流量引导到静态页面,例如我创建的app_offline.html.(我实际上并不会使用app_offline.html,因为这显然会使应用程序离线以获取内部地址.)

Car*_*res 19

您可以使用URL Rewrite(http://www.iis.net/download/URLRewrite).然后你可以删除web.config,内容如下:

<configuration>
  ...
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="External IP" stopProcessing="true">
          <match url="site-under-construction\.htm" negate="true" />
          <conditions>
            <add input="{REMOTE_ADDR}" pattern="192\.168\.\d+\.\d+" ignoreCase="false" negate="true" />
            <add input="{REMOTE_ADDR}" pattern="::1" ignoreCase="false" negate="true" />
            <add input="{REMOTE_ADDR}" pattern="127\.0\.0\.1" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Redirect" url="/site-under-construction.htm" redirectType="Found" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  ...
</configuration>
Run Code Online (Sandbox Code Playgroud)

它基本上只是应用此规则,如果内容不是"正在构建的网站"页面(以防止无限重定向),并且只有在IP地址不是来自192.168.XXX.XXX时才应用此规则(并且不是localhost).

否则它会让他们进入他们要求的任何页面.

请注意,这不应该用作安全机制,因为Remote Addr可能是欺骗性的,但听起来像你的场景应该没问题.