0
votes

I've created and registered custom http module to show maintenance message to user after administrator turns on maintenance mode via configuration change.

When I pass request for html it should return custom html loaded from file, but it returns message: "The service is unavailable." I can't find that string in my entire solution. Custom log message from custom maintenance module is written to log4net logs.

... INFO DdiPlusWeb.Common.MaintenanceResponder - Maintenance mode is on. Request rejected. RequestUrl=...

Seems something is miss configured in IIS on Azure. Something intercepts my 503 response. How to fix it?

Module code

    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        if (AppConfig.Azure.IsMaintenance)
        {
            MaintenanceResponder responder = new MaintenanceResponder(context, MaintenaceHtmlFileName);
            responder.Respond();
        }
    }

Interesting part of responder code.

    private void SetMaintenanceResponse(string message = null)
    {
        _context.Response.Clear();
        _context.Response.StatusCode = 503;
        _context.Response.StatusDescription = "Maintenance";
        if (string.IsNullOrEmpty(message))
        {
            _context.Response.Write("503, Site is under maintenance. Please try again a bit later.");
        }
        else
        {
            _context.Response.Write(message);
        }
        _context.Response.Flush();
        _context.Response.End();
    }

EDIT: I lied. Sorry. Maintenance module returns the same message for requests that expect json or html.

1

1 Answers

0
votes

This answer led me to the solution.

I've added another line to SetMaintenanceResponse method.

_context.Response.TrySkipIisCustomErrors = true;

It works now. Here is more about what it exactly means.