Julia
Julia

Reputation: 23

Redirect from Offline IIS to Maintenance Site

To show people that the ASP.Net Application on the IIS Applicationpool is down for maintenance instead of an legitimate error, I need to redirect anyone calling a part (from bookmarks as well) of the application to an universal maintenance-page.

First I tried the route of using App_Offline in the root directory of the app. To no avail (IIS is down so the site cant be run). Then I tried the http-redirection which didn't work, for the same reason.

Upvotes: 2

Views: 3926

Answers (2)

Gabriel Luci
Gabriel Luci

Reputation: 40928

You don't need to stop your app pool. The existence of app_offline.htm will shut down your application. There are more details about how it works here.

However, that won't stop IIS from serving static HTML files. If you have static HTML files as part of your application, then you will have to redirect some other way. You could create a different site in IIS with your maintenance page. Then remove the binding for your live site and add it to your maintenance site while you do the work. Then move it back later.

Update: Here is some PowerShell I wrote that will wait until all connections are closed. It just looks at ports 443 and 80. You might need to modify it depending on your website:

$TCPProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()

Do {
    $StillConnections = $FALSE
    $Connections = $TCPProperties.GetActiveTcpConnections()
    foreach ($Connection in $Connections) {
        if ($Connection.LocalEndPoint.Port -eq "443") {
            $StillConnections = $TRUE
            Break
        }
    }
    Start-Sleep -s 2
} While($StillConnections) 

Do {
    $StillConnections = $FALSE
    $Connections = $TCPProperties.GetActiveTcpConnections()
    foreach ($Connection in $Connections) {
        if ($Connection.LocalEndPoint.Port -eq "80") {
            $StillConnections = $TRUE
            Break
        }
    }
    Start-Sleep -s 2
} While($StillConnections) 

Upvotes: 2

Jalpa Panchal
Jalpa Panchal

Reputation: 12749

If you stop a Web site, means the Web site no longer listens for requests on all of its bindings. This prevents any subsequent requests from being received by your applications in the Web site; new connections to your Web site will fail as if it didn't exist.

So first start the application pool and create a temporary page which is used to redirect all the pages.

Below is URL rewrite rule which redirects all the pages to the under-construction page.

<rule name="RequestBlockingRule1" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{URL}" pattern=".*" />
                    <add input="{REQUEST_URI}" pattern="temp.html" negate="true" />
                </conditions>
                <action type="Redirect" url="temp.html" />
            </rule>

enter image description here

if you want to redirect to another site you can set another site url in action URL value.

Upvotes: 0

Related Questions