我正在构建一个使用nodejs express来提供rest api服务的应用程序。我使用iisnode module.Everything完美地在windows server 2012上托管了这个应用程序。问题是,当我从节点应用程序返回404(未经授权)消息时,端点正在接收带有iis错误页面的401http状态。有没有其他方法来解决这个问题。
这是我的webconfig文件
<!-- indicates that the hello.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<!-- use URL rewriting to redirect the entire branch of the URL namespace
to hello.js node.js application; for example, the following URLs will
all be handled by hello.js:
http://localhost/node/express/myapp/foo
http://localhost/node/express/myapp/bar
-->
<rewrite>
<rules>
<rule name="/">
<match url="/*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>我在nodejs应用程序中的代码如下
if(clienttoken!=servertoken)
{
res.json(401, 'unauthorized');
res.end();
}

提前感谢
发布于 2016-11-03 08:15:38
使用IIS时,如果您希望将错误直接从Node应用程序返回给请求者,而不希望IIS使用默认错误页拦截它们,请使用existingResponse属性设置为PassThrough的<httpErrors>元素
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>发布于 2016-10-21 04:57:37
IIS隐藏了错误的“详细信息”(您的json响应),因为默认情况下,错误设置为DetailedLocalOnly,这意味着将为来自运行网站的计算机的请求显示错误详细信息,但为任何外部请求显示该错误代码的通用IIS错误页面。
相反,将401error设置为Detailed应该允许您的json响应通过:
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly">
<remove statusCode="401" />
<error statusCode="401" errorMode="Detailed"/>
</httpErrors>
</system.webServer>
</configuration>详情请参见https://www.iis.net/configreference/system.webserver/httperrors。
https://stackoverflow.com/questions/40147118
复制相似问题