I almost went crazy with this one.

The Scenario :-

I installed IIS 7.5 on a fresh Windows 2008 box. Got a website up and running on it. Then added a Virtual Directory for all the site’s assets and thought I am done. But no! None of the assets were visible in browser. I tried in different browsers but no use. I then tried browsing to the images directly in the address bar. Then I noticed that they were all throwing 401 errors. 401. To be more precise :- 401 – Unauthorized: Access is denied due to invalid credentials.

I thought this must be one of the permissions issue. I went ahead and added all the possible options to the physical path. ie IIS_USRS, IUSR, ANONYMOUS, NETWORK SERVICE. Ofcourse, I didn’t add them in one go. I added them one by one after searching on Google for a possible solution first. The whole process took about 2-3 hours. But no use. Images still won’t work.

Source of the Problem :-

All these assets, I had basically uploaded them as a large zip file on the server and then unzipped them into physical path of the virtual directory. And the zip file was created on my Mac. Who would assume that this will be the problem but it was the problem indeed. Apparently, Windows 2008 encrypts all the files while unzipping any file that was zipped up on a Mac.  It’s also worth mentioning that the zip file was downloaded from a https server. So whether it was the https or the Mac, I am not entirely sure yet, but one of those caused the problem. Windows 2008 makes all the files green which is a sign that it has encrypted them.

And IIS does not serve any files that are encrypted. Hence, the 401!

The Solution :-

Select all the green files/folders, go to Properties, then ‘Advanced’ and uncheck ‘Encrypt contents to secure data’

Once you do this, Windows will take a few minutes to do all the de-cryption. Once that’s done, you should be back to normal and back in business 🙂

I hope this helps someone else save numerous number of hours.

Tagged with:  

12 Responses to IIS 7.5 Virtual Directory Error : 401 UnAuthorized

  1. Shaun McCran says:

    Hi,
    This happens to me all the time, if this fixes it then I’ll be very impressed, I normally have to copy and paste the files again, to re do the file permissions.

    Fingers crossed 🙂

  2. Anuj Gakhar says:

    Hi Shaun, that actually fixed it for me and didn’t have to copy/paste again.

  3. Jay P says:

    Thanks! I had the same issue and this fixed it.

  4. Scott Rago says:

    I am sending you an early thank you, I have yet to try this, but I think it’s gonna be the solution I’ve been searching for and was then lucky enough to find your post. Thanks in advance, got my fingers crossed. 🙂

  5. tito says:

    This is helpful, well i dont know about windows 2008, thus this post applicable for windows 7 if things exist with same problem? im confused about this but thank you anyway for this post.

    Best regards,
    Tito

  6. juries says:

    Kinda sure that this will solve my issues and I’m confident to solve this. Just can’t wait to try it..thank you much for this blog!

  7. amac44 says:

    I lost 2-3 hours of my life on this one, on the Friday of a holiday weekend no less. Been working with IIS for 5 years and never encountered this.

  8. Steve says:

    Had this problem too and I was lucky enough to come across this article quite quickly, which has solved my problem. Key indicator is that the folders and files appear in green in Windows Explorer showing that they are encrypted.

  9. paul says:

    thank you so much for posting this solution. I spent the last hour following the exact same process as you did..

    The unchecking of encrypt contents fixed it for me..

  10. Dirk says:

    Sweet! That helped a bunch. IIS does not serve encrypted files. Good to know.

  11. Bhanu chowdary says:

    Wasted all my time in changing permissions…such a noob I am ….thanks bro… A big hug.. Should work as expected….will try it tommorow at work

  12. asheesh says:

    This is wonderful post and no tech forum(Microsoft) covers this 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 445 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: