401 Returned for every 5th call in an ASP.NET MVC application that returns JSON

These are nuts.

I have an ASP.NET MVC application that uses Windows authentication, which, by the way, interacts with several components of the JJJ ExtJs component, returning JSON data to them.

The problem is that even after successful user authentication, every 5th request to capture some JSON data from MVC results in TWO โ€œUnauthorizedโ€ 401 responses followed by a โ€œ200 OKโ€ response. Again, this happens every fifth call ... why? I have no idea.

Interestingly, each response contains the expected JSON !!!

Does anyone else experience this behavior or have any ideas on why this is happening?

Thanks - wg

+4
source share
2 answers

Windows Authentication seems to be working by design:

How to stop 401 response from TFS 2008

I had the same problem with an ASP.NET MVC application running on IIS 6 but using forms authentication. This drove me crazy until I realized that our server is configured for NTLM authentication for each request, as it is an internal intranet server. So this is really not a problem, since the request handles perfectly after a 200 response and does not seem to load load time at all.

+3
source

It happened to me once with me, and in my case it happened because I had a virtual web folder using two different authentication methods: Windows Authentication and Basic Authentication.

Each so often, IIS will try and authenticate the user using Windows authentication, instead of the basic HTTP authentication that I had in mind to use (this happened especially in Internet Explorer) and return an Unauthorized response.

Try disabling authentication methods that you are not using and see what happens.

0
source

All Articles