【问题标题】:Custom maintenance mode module does not work on Azure Web Role自定义维护模式模块不适用于 Azure Web 角色
【发布时间】:2014-10-07 09:27:03
【问题描述】:

我创建并注册了自定义 http 模块,以便在管理员通过配置更改打开维护模式后向用户显示维护消息。

当我传递对 html 的请求时,它应该返回从文件加载的自定义 html,但它返回消息:“服务不可用。”我在整个解决方案中找不到该字符串。来自自定义维护模块的自定义日志消息被写入 log4net 日志。

... 信息 DdiPlusWeb.Common.MaintenanceResponder - 维护模式已打开。请求被拒绝。 RequestUrl=...

似乎在 Azure 上的 IIS 中配置了一些东西。有东西拦截了我的 503 响应。如何解决?

模块代码

    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();
        }
    }

响应者代码中有趣的部分。

    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();
    }

编辑:我撒谎了。对不起。对于需要 json 或 html 的请求,维护模块返回相同的消息。

【问题讨论】:

    标签: iis azure azure-web-roles httpmodule


    【解决方案1】:

    This 的回答让我找到了解决方案。

    我在 SetMaintenanceResponse 方法中添加了另一行。

    _context.Response.TrySkipIisCustomErrors = true;
    

    现在可以了。 Here 更多的是关于它的确切含义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-15
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多