css was not loaded because its MIME type, "text/html", is not "text/css"

Viewed 26192

I got this error while working with web app. This is my master page

<head runat="server">
    <link href="Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>

This is the error:

Error: The stylesheet http://localhost:55381/Login.aspx?ReturnUrl=%2fStyles%2fSite.css was not loaded because its MIME type, "text/html", is not "text/css".
Source File: http://localhost:55381/Login.aspx
Line: 0
6 Answers

@DavidPrecious gave a great answer that led me to the solution.

In my case, the local computer's Users group needed to be given Read permissions to the c:\Inetpub folder in order to allow the static content to be delivered properly.

Another possibility: you've modified your .htaccess file to serve css as html. Maybe something like this, for example:

<filesMatch "\.(htm|html|css|js)$">
ForceType 'text/html; charset=UTF-8'
</filesMatch>

You will want to remove the css from the first line if you've done this.

For me it was an nginx configuration problem, in the file where you declare the path to your static content. I had to move /etc/nginx/mime.types out of the http{} block and further down into where I was serving the static content from. It could similarly be an apache or IIS problem as well, depending on your technology stack.

location / {
   include             /etc/nginx/mime.types;
   root                /path/to/static/content;
   try_files $uri /index.html = 404;
}
Related