asp.netiisiis-7app-offline.htm

Is there a way to shut down an *entire* IIS site and all applications with a friendly message?


Currently we have a multiple sites with multiple virtual applications. Like so:

Site1
    /app1
    /app2
    /app3

Site2
    /app1
    /app2
    /app3

In this scenario, "app1", "app2" and "app3" for both sites point to the same physical folder. We're using IIS 7.0 and .NET 4.0.

The goal is to shutdown Site1 and any access to any of its virtual applications while showing a friendly message but not shutdown Site2 in the process. If we put an app_offline.htm file at the root, it works great...when users navigate to the root. However, if a user navigates directly to one of the virtual applications, the app_offline.htm at the root is ignored. Placing an app_offline.htm into each virtual directory isn't an option as that would shut down both Site1 and Site2 for that application.

Obviously, we can stop the application pools but that shows the ugly 503 Service Unavailable message and I prefer not changing the 503 error page itself.


Solution

  • I would change the physical path for Site1 to point somewhere else like /siteoffline with a default.htm file there that has your friendly message in it. Then I would add a URL redirect rule that would match all requests: (.*) and redirect to /default.htm. The rules would look like this:

        <rewrite>
            <rules>
                <clear />
                <rule name="DontRedirectDefault" stopProcessing="true">
                    <match url="default.htm" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="None" />
                </rule>
                <rule name="RedirectAllToRoot" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAny" trackAllCaptures="false" />
                    <action type="Redirect" url="/default.htm" />
                </rule>
            </rules>
        </rewrite>
    

    The first rule is there to skip the redirect if we're already looking at default.htm. Anything else will drop to the 2nd rule and redirect everything to /default.htm.