iisip-restrictions

IP restriction error message


Say, If I restrict access to a site's subfolder using "IP address and domain restrictions", what would be the IIS error message I would be getting? I need to use a custom error message like "Your IP is not allowed to access this site", but would that be possible? I am asking if the same same error code (like a generic access denied that is returned for Certificate error) is returned for this, then I won't be able to use it.

Is it possible to get a unique error when a request fail at the "IP address and domain restrictions" rule?


Solution

  • IIS will raise a HTTP 403.6 - Forbidden: IP address rejected.

    If you want to display a custom error page then go to your website within the IIS Manager and look for "Error Pages" under the IIS section, on the right hand side under "Actions" click "Add...", fill out the window using status code 403.6 and choose your action.

    This can also be achieved by modifying your websites web.config file, just add an <error> entry to the <httpErrors> section as shown below:

    <system.webServer>
        <httpErrors>
            <error statusCode="403" subStatusCode="6" path="/errors/iprestricted.html" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>