【Azure 应用服务】Web.config中设置域名访问限制,IP地址限制访问特定的页面资源 (Rewrite)

问题描述

问题一:web app已经绑定了域名,例如是www.a.com,现在只允许使用www.a.com 访问,如果使用默认的域名xxxx.chinacloundsites.cn访问的时候,需要显示一个错误的页面该如何怎么设置呢

问题二:有一个特定的页面/admin/login/index.html只想特定的IP访问,该如何去写配置web.config呢?

以上问题都是通过配置Rewrite的规则来实现:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <rewrite>
        <rules>
       ########## 解决问题一,根据域名进行调转 ########### <rule name="WWW Redirect" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{HTTP_HOST}" pattern="^www.a.com$" /> </conditions> <action type="Redirect" url="http://www.a.com/{R:0}" redirectType="Permanent" /> </rule>
       ########## 解决问题二,根据IP地址调转 ###########
            <rule name="special IP Rule" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{REMOTE_HOST}" pattern="^192.168.1.16" />
                </conditions>
                <action type="Redirect" url="/admin/login/index.html" />
            </rule>
        </rules>
    </rewrite>
</system.webServer> 
原文地址:https://www.cnblogs.com/lulight/p/14332319.html