HTTP Error 401 on AJAX POST

While working on a project at work where it was needed to let the user attach one or multiple files to a form by dragging, dropping and uploading them to the server using AJAX, I encounter this error:

I'm working on a Windows environment, IIS7, and my target framework is 4.0 (and yeah, I'm also developing this web app in VS2015).

Doing some research, I found that this problem could be caused because the allowed size for uploads on IIS7 was not big enough, so I needed to increase it. Unfortunately, increasing the maximum allowed size didn't work and I'd still get the HTTP Error 401 code.

I also tried adding a requestLimits configuration tag to my web.config file:

Alas, that didn't help either...

So, after some frustration and more research, what did fix my issue was to add this configuration tag to the web.config file:

I was then able to upload files (up to 30 MB) without a problem. You could increase the number to 2147483647 if you need to upload files up to 2 GB.

Hope this helps, and perhaps, save you some time and frustration.

Happy coding!