Help Needed for Asp.Net Extension

As most of you know, if I drop the file named app_offline.htm in the asp.net root application, it will take the application offline as described here .

You also know that although this is great, IIS actually returns 404 code when this happens, and Microsoft is not going to do anything about it as indicated here .

Now, since Asp.Net is generally so extensible, I think there should be no way to overcome this status code in order to return 503 instead? The problem is that I don’t know where to start looking for this change.

HELP!

+4
source share
4 answers

The processing of app_offline.htm is hard-coded in the ASP.NET pipeline and cannot be changed: see CheckApplicationEnabled() in HttpRuntime.cs , where it throws a very non-configurable 404 error if the application is considered offline.

However, creating your own HTTP module to do something similar is, of course, trivial - the OnBeginRequest handler may look like this in this case (the implementation for HttpHandler is shown, but the idea is exactly the same in HttpModule):

 Public Sub ProcessRequest(ByVal ctx As System.Web.HttpContext) Implements IHttpHandler.ProcessRequest If IO.File.Exists(ctx.Server.MapPath("/app_unavailable.htm")) Then ctx.Response.Status = "503 Unavailable (in Maintenance Mode)" ctx.Response.Write(String.Format("<html><h1>{0}</h1></html>", ctx.Response.Status)) ctx.Response.End() End If End Sub 

This is just the starting point, of course: by making the returned HTML a little friendlier, you can also display a good “we'll be back” page for your users.

+5
source

You can try disabling it in the web.config file.

 <httpRuntime enable = "False"/> 
+1
source

Perhaps you could do this by writing your own HTTP handler (the .NET component that implements the System.Web.IHttpHandler interface).

There is a good article for primers here: link text

+1
source

The advantage of app_offline.htm and httpRuntime enable = "False", highlighted in the first link in the original question, is that the application’s application domain is no longer loading, which may be desirable for significant changes to the site. A slight modification to leppie's answer (which still serves 404) is to add defaultRedirect to another site that will allow the source site to be off, then the target site will serve as a simple 503-page page

web.config source website

 <httpRuntime enable="false" /> <customErrors mode="On" defaultRedirect="/maintainance.aspx"/> 

maintainance.aspx at dest site

 <%@Page Language="C#"%> <% Response.StatusCode = 503; Response.Write("App offline for maintainance"); %> 
0
source

Source: https://habr.com/ru/post/1276919/


All Articles