开发者

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

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


Looks like your code is requiring a login to access the CSS stylesheet, and returning a HTML login page instead of the CSS.

To verify, try pasting the URL to the stylesheet into your browser, for instance http://localhost:55381/Styles/Site.css - if you get a login page instead of CSS, that's what you need to fix.


Try this:

<location path="~/Styles">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>

Where Styles is the folder that contains style sheet. I solved it this way


@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.


This is more likely an issue at your server side. You request style sheet page Styles/Site.css from the server of type text/css, but your server might be responding to this request with test/html. I had this issue when my server was running in Python and my server was replying to requested css files with header text/html (as that of my index.html file). I re-arranged my server code and assigned the correct headers to its corresponding pages and my issue got resolved.


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜