0

I have an MVC website and occasionally on my test server, the CSS will not load.

It seems to work fine on my local machine.

What appears to be happening is that it is requesting the CSS file with the wrong MIME type and I get the error "The stylesheet was not loaded because its MIME type, "text/html", is not "text/css". It then redirects me to the login page.

The line of code for my CSS is:

<link rel="stylesheet" type="text/css" href="/Resources/CSS/main.css">

I have also checked the MIME types in IIS and it seems to be set up fine.

If I soft reload the page, the CSS appears fine, but if I hard refresh the page I get that error, the CSS won't load and it redirects me to the login page, as if I do not have sufficient privileges.

When I go to the source code, I cannot browse to the CSS file by clicking on the url, although the file is physically there if I type in the path.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Trent Stewart
  • 841
  • 1
  • 9
  • 18
  • try to rename your folders in lowercase, may be that was a problem – you-rick Nov 25 '14 at 21:40
  • 1
    Typically this is because of an authentication issue. You are requesting the CSS file, but IIS is seeing you as not authorized and is returning a unauthorized response (which is where the html part of this is coming in). Then you are getting redirected to the login screen, which is what you would expect. Check your permissions and as well, check that the .NET pipeline is not also trying to serve up static content (http://stackoverflow.com/questions/11048863/modules-runallmanagedmodulesforallrequests-true-meaning) – Tommy Nov 25 '14 at 22:09
  • Thanks Tommy you were right. – Trent Stewart Nov 25 '14 at 22:16
  • @TrentStewart No problem, should I post this as an answer? – Tommy Nov 25 '14 at 22:17
  • 1
    I posted an answer already but you can if you want – Trent Stewart Nov 25 '14 at 22:18
  • @TrentStewart - nope, all good. Just didn't want to answer to be buried in a comment. Be sure to accept when the timer runs out :) – Tommy Nov 25 '14 at 22:19

2 Answers2

0

Also, be careful using caps in your paths. It's just one of those things that can trap you if you don't use them everywhere or if you end up using a server that just doesn't like them!

emailcooke
  • 271
  • 1
  • 4
  • 17
  • I don't believe this is the issue, as the path in my html has the same capitalisation as the actual directory. And the css will load sometimes, but has an authentication MIME type error other times. – Trent Stewart Nov 25 '14 at 21:54
0

Thanks for all the help, it turned out this was an authentication setting in IIS. It had Windows Authentication enabled but we have a custom authentication module. By disabling Windows authentication, everything is back to normal.

Trent Stewart
  • 841
  • 1
  • 9
  • 18