我正在构建一个应用程序,我使用nodejsexpress来执行rest api服务。 我使用 iisnode 模块在 Windows Server 2012 上托管该应用程序。一切都很完美。 问题是,当我从 Node 应用程序返回 404(未经授权)消息时,端点正在接收带有 iis 错误页面的 401 http 状态。 有没有其他方法可以解决这个问题。
这是我的 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();
}
提前致谢
最佳答案
使用 IIS,如果您希望将错误直接从 Node 应用程序返回给请求者,而 IIS 不使用默认错误页拦截它们,请使用 <httpErrors>
带有 existingResponse
的元素属性设置为 PassThrough
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>
关于asp.net - iisnode 401消息返回iis页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40147118/