Search code examples
asp.net-mvcwindows-authentication

IIS is forcing me to login in order to load my CSS and Javascript files when using Windows Authentication on a subdirectory


I have an asp.net MVC application that has one section /admin locked down via windows authentication. I have achieved this by doing the following.

Web.Config

<authentication mode="Windows" />

AdminController

[Authorize]
public class ContactController : Controller
{
   ....
}

This works as it should. When I try to access the /admin URI it prompts me for a windows login.

However, in my /Views/Admin/Index.aspx view, I am linking to two files:

<script src="/media/js/site.js"></script>
<style href="/media/css/styles.css" ... />

For some reason IIS is prompting me for a windows login for each of these files too.

  • If I hit cancel (after the first login), then the page loads, but without any CSS or Javascript.
  • If I remove those tags from my view, then I am only prompted to login one time and it "works".

So why is windows prompting me to authenticate for the CSS & JS files?

Any help would be greatly appreciated.


Solution

  • SOLVED

    As with most problems like this, turns out it was a permissions error.

    I gave "Read" access on the media folder to the windows user that I was logging in with and bam it all works dandy now.