Reputation: 2673
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");
}
}
Upvotes: 4
Views: 4971
Reputation: 16680
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?
Upvotes: 0
Reputation: 7311
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.
Upvotes: 9
Reputation: 34846
App_Offline.html
will do this.
Read about App_Offline.html here.
Upvotes: 5