【问题标题】:app_offline.htm throwing HTTP 500 errors on production boxapp_offline.htm 在生产机器上抛出 HTTP 500 错误
【发布时间】:2011-02-08 00:49:56
【问题描述】:

我为在 IIS7 / Win2008 64 位上运行的 ASP.NET MVC2 应用程序创建了一个 app_offline.htm 文件,并确保它超过 512 字节(现在是 2KB)。在我运行 Visual Studio 2010 的开发盒上,它的工作原理就像一个魅力,但是当我把它放在生产盒上时,我得到的只是一般的 HTTP 500 错误,说“由于发生了内部服务器错误,页面无法显示。”

特别奇怪的是,我没有在应用程序事件日志中记录任何内容,ELMAH 也没有收到任何内容。我已经禁用了自定义错误,为文件添加了 FormsAuthentication 位置异常,确保我没有引用任何其他文件(图像等),但没有任何修复。

我已经阅读了关于 SO 的所有帖子,并在 Google 上搜索了几个小时,但无法弄清楚这一点。有什么想法可能是错的吗?我要拔头发了……

【问题讨论】:

  • 服务器的事件日志中是否有更多信息?
  • 不,这很奇怪——服务器上根本没有抛出任何东西,不在应用事件日志或系统事件日志中。
  • 您是否尝试过从 localhost 访问该站点?有时会显示更多细节。还尝试过 firefox 和/或在 IE 中关闭友好的 http 错误消息,以便向您显示实际错误。
  • 不是来自服务器的本地主机,但我会尝试。我在 Firefox 和 Chrome 中尝试过,但除了一行简单的文本,我什么也没得到。

标签: asp.net asp.net-mvc app-offline.htm


【解决方案1】:

更新:
你的 web.config 中有这个吗?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.web>
        <httpRuntime waitChangeNotification="300" maxWaitChangeNotification="300"/>
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
</configuration>

但还有一个问题。

ASP.NET 会将应用程序卸载为 web.config 更改后,但 它实际上不会重新加载并应用 “waitChange...”设置直到 提出请求。所以你仍然可以 删除 app_offline.htm 和 web.config 中,如果第一次请求 当 dll 只有一半时发生 复制,就会发生异常。到 雪上加霜,例外 将持续存在,直到您更换 临时 web.config 或总 “waitChange…”时间的持续时间 过期了!

要绕过这最后一道障碍,您需要 需要向 上传后的申请 临时 web.config,但在你之前 开始部署应用程序文件。 完整的流程如下:

  1. 添加 app_offline.htm
  2. 将应用程序的 web.config 替换为临时 web.config(如上)
  3. 请求站点上的任何 ASP.NET 资源,以便新的 waitChangeNotification 被“应用”*
  4. 进行任何必要的文件系统更改(部署 bin dll,其他站点 文件)
  5. 用原始应用程序替换临时 web.config web.config
  6. 删除app_offline.htm

*您可能会质疑步骤 2-3 中发生的情况,因为 ASP.NET 关闭了 步骤 1 后的应用程序。确实,它 没有出现在我的事件查看器中 web.config 更改是 注册或“申请”的结果 第 2 步或第 3 步,但无论如何 更新的 waitChangeNotification 在第 3 步之后会应用设置。

More app_offline.htm woes

App_offline.htm gotchas with ASP.NET MVC

【讨论】:

【解决方案2】:

我想出了一个 100% 适合我们部署的解决方案,所以我想我会分享它。

此解决方案将 customErrors 部分添加到 web.config。这将捕获任何未处理的异常。它重定向到 App_Offline.htm,它会一直刷新,直到应用程序重新联机。因此,当应用程序可用时,用户会得到一个很好的加载器。

我希望这会有所帮助:)

批处理文件

copy "C:\www\_App_Offline.htm" "C:\www\App_Offline.htm"
copy /y "C:\www\App_Offline.config" "C:\www\Web.config"

Rem do deploy/publish actions

Rem Note: Our publish replaces/restores the Web.config. You should do that here.
del "C:\www\App_Offline.htm"

App_Offline.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <httpRuntime waitChangeNotification="100" maxWaitChangeNotification="100"/>
    <customErrors defaultRedirect="App_Offline.htm" mode="On">
    </customErrors>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

_App_Offline.htm

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Application Offline</title>
    <meta charset="UTF-8">
    <style>
        .facebook_blockG { background-color: none; border: 3px solid #D6D6D6; float: left; height: 40px; margin-left: 7px; width: 24px; opacity: 0; -moz-animation-name: bounceG; -moz-animation-duration: 1.3s; -moz-animation-iteration-count: infinite; -moz-animation-direction: linear; -moz-transform: scale(0.7); -webkit-animation-name: bounceG; -webkit-animation-duration: 1.3s; -webkit-animation-iteration-count: infinite; -webkit-animation-direction: linear; -webkit-transform: scale(0.7); -ms-animation-name: bounceG; -ms-animation-duration: 1.3s; -ms-animation-iteration-count: infinite; -ms-animation-direction: linear; -ms-transform: scale(0.7); -o-animation-name: bounceG; -o-animation-duration: 1.3s; -o-animation-iteration-count: infinite; -o-animation-direction: linear; -o-transform: scale(0.7); animation-name: bounceG; animation-duration: 1.3s; animation-iteration-count: infinite; animation-direction: linear; transform: scale(0.7); }
        #blockG_1 { -moz-animation-delay: 0.39s; -webkit-animation-delay: 0.39s; -ms-animation-delay: 0.39s; -o-animation-delay: 0.39s; animation-delay: 0.39s; }
        #blockG_2 { -moz-animation-delay: 0.52s; -webkit-animation-delay: 0.52s; -ms-animation-delay: 0.52s; -o-animation-delay: 0.52s; animation-delay: 0.52s; }
        #blockG_3 { -moz-animation-delay: 0.65s; -webkit-animation-delay: 0.65s; -ms-animation-delay: 0.65s; -o-animation-delay: 0.65s; animation-delay: 0.65s; }

        @-moz-keyframes bounceG {
            0% { -moz-transform: scale(1.2); opacity: 0.6; }

            100% { -moz-transform: scale(0.7); opacity: 0; }
        }

        @-webkit-keyframes bounceG {
            0% { -webkit-transform: scale(1.2); opacity: 0.6; }

            100% { -webkit-transform: scale(0.7); opacity: 0; }
        }

        @-ms-keyframes bounceG {
            0% { -ms-transform: scale(1.2); opacity: 0.6; }

            100% { -ms-transform: scale(0.7); opacity: 0; }
        }

        @-o-keyframes bounceG {
            0% { -o-transform: scale(1.2); opacity: 0.6; }

            100% { -o-transform: scale(0.7); opacity: 0; }
        }

        @keyframes bounceG {
            0% { transform: scale(1.2); opacity: 0.6; }

            100% { transform: scale(0.7); opacity: 0; }
        }
    </style>
</head>
<body>

    <div id="overlay" class="trans">
        <div id="overlay-inner" class="trans login">
            <h1 style="line-height:1em; font-size:30pt">Application Offline</h1>
            <h2 style="line-height:1em; width:70%; margin:auto">application is offline for maintenance</h2>
            <div style="width: 128px; margin:40px auto">
                <div id="blockG_1" class="facebook_blockG">
                </div>
                <div id="blockG_2" class="facebook_blockG">
                </div>
                <div id="blockG_3" class="facebook_blockG">
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        function getParameterByName(name) {
            name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
            var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                results = regex.exec(location.search);
            return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
        }
        setTimeout(function () {
            var loc = getParameterByName('aspxerrorpath');
            loc = (loc) ? window.location.protocol + '//' + window.location.host + loc : window.location.href;
            window.location.assign(loc);
        }, 1500);
    </script>
</body>
</html>

【讨论】:

  • 非常有帮助,我为我们的网站进行了调整,效果很好。谢谢!
猜你喜欢
  • 2014-01-13
  • 2011-08-02
  • 1970-01-01
  • 2013-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-04
  • 1970-01-01
相关资源
最近更新 更多