Windows Azure 网站覆盖了我的 node.js 应用程序中的 404 和 500 错误页面 [英] Windows Azure Websites is overriding my 404 and 500 error pages in my node.js app

查看:14
本文介绍了Windows Azure 网站覆盖了我的 node.js 应用程序中的 404 和 500 错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Windows Azure Websites to host a node.js application. So far everything is great except for my custom errors. In my node app I have an error handler that renders a custom 404 and custom 500 error page just fine on my local machine. However, as soon as I publish to azure it overrides the response when I set the statusCode to anything except 200.

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

If I don't pass the 500 or 404 statusCode to the response then this does not happen, but I do want the status codes to make it to the browser. Locally I get my custom error page just fine:

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

However, on azure websites it only returns a single line of text:

页面无法显示,因为发生了内部服务器错误.

The page cannot be displayed because an internal server error has occurred.

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

I tried creating my own web.config to override the default one with custom errors disabled but that didn't seem to have any effect. Here is my 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)%
odejs
ode.exe&quot;"
            logDirectory="....LogFiles
odejs"
            watchedFiles="*.js;iisnode.yml;node_modules*;views*.jade;views*.ejb;routes*.js" />
    </system.webServer>
</configuration>

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

I'm not sure if iisnode (the extension for iis that routes requests to node.js) is responsible for overriding my error pages or if iis itself is responsible. Any suggestions?

推荐答案

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

Well nevermind, I found the issue. If anyone else is having the same problem simply add the following under <system.webServer> in web.config:

<httpErrors existingResponse="PassThrough" />

这篇关于Windows Azure 网站覆盖了我的 node.js 应用程序中的 404 和 500 错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆