4

We have a ASP.NET website in .NET which is running successfully in production. we have frequently maintain our server on a particular downtime. Hence, We need a feature to redirect all request to Site Under maintenance web page at downtime. I've accomplished this task with Custom Handler but my customer isn't happy with that solution. Please suggest some alternate solution.

My Custom Handler code as follows

Added Under web.config

    <system.webServer>
        <modules>
          <add name="CustomModule" type="CustomModule"/>
       </modules>
  </system.webserver>

Added Under Http Handler

public class CustomModule : IHttpModule
    {
        // In the Init function, register for HttpApplication 
        // events by adding your handlers.
        public void Init(HttpApplication application)
        {

            application.EndRequest +=
                (new EventHandler(this.Application_EndRequest));
        }
}

Redirect code goes here

private void Application_EndRequest(Object source, EventArgs e)
        {

            if (fileExtension.Equals(".aspx") == true && filePath.Contains("Contact.aspx") == false)
            {
                context.Response.Redirect("Contact.aspx");
            }
        }
Smaug
  • 2,625
  • 5
  • 28
  • 44
  • 2
    Why isn't the customer happy with this? – David Aug 05 '13 at 17:51
  • It's already in production. So they wouldn't like to implement custom handler. – Smaug Aug 05 '13 at 17:53
  • 1
    http://blogs.msdn.com/b/amb/archive/2012/02/03/easiest-way-to-take-your-web-site-offline-iis-6-0-or-iis-7-5-with-net-4-0.aspx assuming you are on recent iis version – rene Aug 05 '13 at 17:53
  • I'm in .NET 2.0 version – Smaug Aug 05 '13 at 17:54
  • Somebody posted on the link from @rene it could work in 2.0 – hagensoft Aug 05 '13 at 17:56
  • 2
    From your responses, it sounds like you paradoxically want to run custom code, but without deploying any code to the server. You can't accomplish both goals. – Greg Aug 05 '13 at 18:10
  • How about adding a meta refresh tag to the app_offline.html like in [this](http://stackoverflow.com/questions/5411538/how-to-redirect-from-html-page) answer – rene Aug 05 '13 at 18:48
  • @rene - I don't think he'd be able to redirect to the main site with an app_offline. It would probably just redirect back to itself infinitely. – Greg Aug 05 '13 at 18:55
  • @Greg, hmmm, you are probably right...it seems to be a catch 22 in that case... – rene Aug 05 '13 at 19:12

3 Answers3

9

Just use app_offline.htm, explained here and here.

If you want to keep the site down for a specific time period (or to some other external event, etc.) then you could run a (scheduled) script on the server to create or remove the app_offline.htm file when needed.

muratgu
  • 7,241
  • 3
  • 24
  • 26
5

App_Offline.html will do this.

Read about App_Offline.html here.

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
  • I need a feature to redirect from my webpage. because I want to do some automatic time calcualtion for downtime. If then, redirect to maintanance web page – Smaug Aug 05 '13 at 17:58
0

If you can't deploy code to the production server, what about using a scheduled task batch file (or a custom program) to deploy and remove the App_Offline.html file on a schedule?

Greg
  • 16,540
  • 9
  • 51
  • 97