asp.net - iisnode 401消息返回iis页面

标签 asp.net node.js express iis iisnode

我正在构建一个应用程序,我使用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();
}

enter image description here

提前致谢

最佳答案

使用 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/

相关文章:

c# - 从 C# 程序连接基于 node.js 的 socket.io WebSocket 服务器

javascript - 是否可以使用快速路线正则表达式中的捕获组?

.net - 如何知道哪个应用程序正在使用 GAC 中的程序集?

node.js - face-api.js 从磁盘加载图像文件

javascript - 仅针对 IE8 以上设置样式

javascript - html 标签按字面意思显示在浏览器中

Node.js 通过查询字符串传递参数

node.js - 将使用node-gd生成的图像发送到客户端

c# - Devexpress ASPxGridView GetSelectedFieldValues 无法获取值

c# - 将位于 WebDAV 中的 .PDF 直接打开到 Acrobat(或默认的 PDF 应用程序)中