在返回 JSON 的 ASP.NET MVC 应用程序中,每 5 次调用就会返回 401
这太疯狂了。
我有一个使用 Windows 身份验证的 ASP.NET MVC 应用程序,除其他外,它通过向多个 ExtJs Javascript 组件返回 JSON 数据来与它们进行交互。
问题是,即使用户成功通过身份验证,每 5 个从 MVC 获取一些 JSON 数据的请求都会导致两个“401 Unauthorized”响应,后跟一个“200 OK”响应。 同样,这种情况每 5 次调用就会发生一次……为什么? 我不知道。
有趣的是,每个响应都包含预期的 JSON!!!
其他人经历过这种行为或者对为什么会发生有任何想法吗?
谢谢-wg
This is nuts.
I have an ASP.NET MVC application using Windows authentication that, amongst other things, interacts with a number of ExtJs Javascript components by returning JSON data to them.
The problem is that even after the user is successfully authenticated, every 5th request to grab some JSON data from MVC results in TWO "401 Unauthorized" responses followed by a "200 OK" response. Again, this happens every 5th call ... why? I have no idea.
Interestingly enough, each response contains the expected JSON!!!
Anyone else experiencing this behavior or have any ideas on why its happening?
Thanks - wg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来 Windows 身份验证的设计工作原理如下:
如何停止来自 TFS 2008 的 401 响应
对于在 IIS 6 上运行但使用 Forms 身份验证的 ASP.NET MVC 应用程序,我也遇到了同样的问题。 这让我抓狂,直到我意识到我们的服务器设置为通过 NTLM 对每个请求进行身份验证,因为它是内部 Intranet 服务器。 所以这实际上不是问题,因为请求在 200 响应之后处理得很好,并且似乎根本没有拖延加载时间。
It appears this is how Windows Authentication works by design:
How do I stop 401 responses from TFS 2008
I had this same issue with an ASP.NET MVC application running on IIS 6, but using Forms authentication. It drove me crazy until I realized that our server is setup to authenticate via NTLM for every request, since it's an internal intranet server. So it's really a non-issue, since the request processes fine after the 200 response, and doesn't seem to bog down the load time at all.
我曾经遇到过这种情况,就我而言,这是因为我让虚拟 Web 文件夹使用两种不同的身份验证方法:Windows 身份验证和基本身份验证。
IIS 经常会尝试使用 Windows 身份验证而不是我本来打算使用的基本 HTTP 身份验证来对用户进行身份验证(这种情况尤其发生在 Internet Explorer 中),并返回“未经授权”响应。
尝试禁用您不使用的身份验证方法,看看会发生什么。
I had this happen to me once, and in my case, it was because I had the virtual web folder use two different authentication methods: Windows Authentication and basic authentication.
Every so often IIS would try and authenticate the user using Windows Authentication instead of the basic HTTP authentication I had meant it to use (this happened most especially in Internet Explorer) and return an "Unauthorized" response.
Try disabling authentication methods that you aren't using, and see what happens.