【问题标题】:Windows Azure Websites is overriding my 404 and 500 error pages in my node.js appWindows Azure 网站覆盖了我的 node.js 应用程序中的 404 和 500 错误页面
【发布时间】:2013-02-15 04:01:13
【问题描述】:

我正在使用 Windows Azure 网站来托管 node.js 应用程序。到目前为止,除了我的自定义错误之外,一切都很好。在我的节点应用程序中,我有一个错误处理程序,可以在我的本地机器上呈现自定义 404 和自定义 500 错误页面。但是,一旦我发布到 azure,当我将 statusCode 设置为 200 以外的任何值时,它都会覆盖响应。

如果我没有将 500 或 404 statusCode 传递给响应,则不会发生这种情况,但我确实希望将状态代码发送到浏览器。在本地我得到我的自定义错误页面就好了:

但是,在 azure 网站上它只返回一行文本:

由于发生内部服务器错误,页面无法显示。

我尝试创建自己的 web.config 以覆盖禁用自定义错误的默认配置,但这似乎没有任何效果。这是我的 web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <customErrors mode="off" />
    </system.web>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
        </handlers>
        <rewrite>
            <rules>
                <rule name="StaticContent">
                    <action type="Rewrite" url="public{REQUEST_URI}"/>
                </rule>
                <rule name="DynamicContent">
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
                    </conditions>
                    <action type="Rewrite" url="app.js"/>
                </rule>
            </rules>
        </rewrite>
        <iisnode
            debuggingEnabled="true"
            devErrorsEnabled="true"
            debuggerPathSegment="debug"
            nodeProcessCommandLine="&quot;%programfiles(x86)%\nodejs\node.exe&quot;"
            logDirectory="..\..\LogFiles\nodejs"
            watchedFiles="*.js;iisnode.yml;node_modules\*;views\*.jade;views\*.ejb;routes\*.js" />
    </system.webServer>
</configuration>

我不确定iisnode(将请求路由到node.js 的iis 扩展)是否负责覆盖我的错误页面,或者iis 本身是否负责。有什么建议吗?

【问题讨论】:

  • 这对我不起作用,最终的原因是我的 web.config 中有一个 &lt;staticContent&gt; 部分。为我删除修复它:stackoverflow.com/questions/22549579/…
  • 感谢@MattGreer 提供的信息。是您自己添加了 &lt;staticContent&gt; 元素还是 Azure 网站默认 web.config 中的新元素?如果它是默认 web.config 的一部分,那么我想更新此答案以反映您的更正。
  • 我自己添加它是为了让 IIS 为 SVG 提供服务(默认情况下不这样做)

标签: node.js azure web-config iisnode


【解决方案1】:

没关系,我发现了问题。如果其他人遇到同样的问题,只需在 web.config 中的 &lt;system.webServer&gt; 下添加以下内容:

<httpErrors existingResponse="PassThrough" />

【讨论】:

    【解决方案2】:

    在 Windows azure 中托管的 MVC 项目也有类似的问题。在 IIS 下托管的本地计算机上工作正常,但在实时计算机上,我收到以下错误“您要查找的资源已被删除、更改名称或暂时不可用。”

    将此添加到 system.webServer 下的 web 配置中节省了我的时间

    我的 web.config 看起来像这样

    <system.web>
       ***
        <customErrors mode="RemoteOnly" defaultRedirect="~/Error/PageNotFound">
          <error statusCode="404" redirect="~/Error/PageNotFound" />
          <error statusCode="500" redirect="~/Error/ServerError"/>
        </customErrors>
      </system.web>
    ***
    <system.webServer>
        <httpErrors existingResponse="PassThrough" />
    </system.webServer>
    

    【讨论】:

      猜你喜欢
      • 2023-04-11
      • 2010-11-10
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多