Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom http status code for specific resource in IIS

Tags:

http

iis

iis-7

I have a web site with a single 'app_offline.htm' file. How can i configure IIS to return it with specific status code (say, 209) instead of default one (200)?

like image 621
UserControl Avatar asked Dec 21 '22 06:12

UserControl


1 Answers

An alternative to using the 'app_offline.htm' feature of ASP.Net could be to use the IIS URL Rewrite Module, it has a huge bag of tricks and setting custom response codes is one of them.

If the content of the page is not important, only the response code, then with that module you can configure a rule that will return a blank response with a 209 code to any request as long as the rule is enabled.

That will materialise in your web.config as something like this:

<configuration>
    <system.webServer>       
        <rewrite>
            <rules>
                <rule name="app_offline" stopProcessing="true">
                    <match url=".*" />
                    <action type="CustomResponse" statusCode="209" statusReason="System unavailable" statusDescription="The site is currently down for maintenance, or something." />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
like image 98
woodysan Avatar answered Dec 24 '22 00:12

woodysan