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");
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With