首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iisnode 401消息返回iis页

iisnode 401消息返回iis页
EN

Stack Overflow用户
提问于 2016-10-20 14:38:33
回答 2查看 1.1K关注 0票数 2

我正在构建一个使用nodejs express来提供rest api服务的应用程序。我使用iisnode module.Everything完美地在windows server 2012上托管了这个应用程序。问题是,当我从节点应用程序返回404(未经授权)消息时,端点正在接收带有iis错误页面的401http状态。有没有其他方法来解决这个问题。

这是我的webconfig文件

代码语言:javascript
复制
<!-- 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应用程序中的代码如下

代码语言:javascript
复制
 if(clienttoken!=servertoken)
{
    res.json(401, 'unauthorized');
    res.end();
}

提前感谢

EN

回答 2

Stack Overflow用户

发布于 2016-11-03 08:15:38

使用IIS时,如果您希望将错误直接从Node应用程序返回给请求者,而不希望IIS使用默认错误页拦截它们,请使用existingResponse属性设置为PassThrough<httpErrors>元素

代码语言:javascript
复制
<configuration>
  <system.webServer>
    <httpErrors existingResponse="PassThrough" />
  </system.webServer>
</configuration>
票数 4
EN

Stack Overflow用户

发布于 2016-10-21 04:57:37

IIS隐藏了错误的“详细信息”(您的json响应),因为默认情况下,错误设置为DetailedLocalOnly,这意味着将为来自运行网站的计算机的请求显示错误详细信息,但为任何外部请求显示该错误代码的通用IIS错误页面。

相反,将401error设置为Detailed应该允许您的json响应通过:

代码语言:javascript
复制
<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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40147118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档