CSS 资源被解释为样式表,但在 ASP.NET IIS 中使用 MIME 类型 text/html 传输
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6089070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resource interpreted as Stylesheet but transferred with MIME type text/html in ASP.NET IIS
提问by sansknwoledge
i am having a login page when executed the page is stripped out of css
.
我在执行时有一个登录页面,该页面被剥离css
。
I found out this message from from chrome debugger. I am using asp.net 2008.
我从 chrome 调试器中发现了这条消息。我正在使用 asp.net 2008。
Any ideas?
有任何想法吗?
<head id="Head1" runat="server">
<title>CalibPro</title>
<link href="css/Login.css" rel="stylesheet" type="text/css" />
<link href="css/Common.css" rel="stylesheet" type="text/css" />
</head>
edited as per @robx advice.
根据@robx 建议进行编辑。
回答by Variant
Seems to me like the problem is in your IIS configuration. it might be configured to deliver .css files with text/html MIME type.
在我看来,问题出在您的 IIS 配置中。它可能被配置为提供具有 text/html MIME 类型的 .css 文件。
Try going to the MIME types configuration on the web server and see if you can spot anything there.
尝试转到 Web 服务器上的 MIME 类型配置,看看是否可以在那里发现任何内容。
The correct MIME type for .css files is text/css.
.css 文件的正确 MIME 类型是 text/css。
You can also have a look on the HTTP header parameters with some HTTP sniffer such as fiddler.
您还可以使用一些 HTTP 嗅探器(例如 fiddler)查看 HTTP 标头参数。
Updating: The accepted answer should be the one pointed by @brett-pennings! Just providing static contents, the error vanished automatically.
更新:接受的答案应该是@brett-pennings 指出的答案!只需提供静态内容,错误就会自动消失。
回答by Brett Pennings
Make sure you enable "Static Content" in IIS Windows Features.
确保在 IIS Windows 功能中启用“静态内容”。
回答by Elwi
This is a problem when you are using rewrite url in IIS (in my case it was that), you need to add this entry in your web.config file of your web before the entry of rewrite, something like this:
当您在 IIS 中使用 rewrite url 时,这是一个问题(在我的情况下是这样),您需要在 rewrite 条目之前将此条目添加到您的 web 的 web.config 文件中,如下所示:
<rule name="CSS" stopProcessing="true">
<match url=".css" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
</conditions>
<action type="None" />
</rule>
<rule name="mod_write" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="%(REQUES_FILENAME)" matchType="IsDirectory" negate="true" />
<add input="%(REQUES_FILENAME)" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="false" />
</rule>
回答by Leniel Maccaferri
Oh dear lord! This was one of those errors that seems to come from nowhere... I was scratching my head for almost 1 hour trying to identify what was causing just 1 specific .css
file to show a message very similar in Chrome's console window:
哦亲爱的主!这是似乎无处不在的错误之一......我摸索了将近 1 个小时,试图找出导致仅 1 个特定.css
文件在 Chrome 的控制台窗口中显示非常相似的消息的原因:
Resource interpreted as Stylesheet but transferred with MIME type text/plain
You see it's text/plain
instead of text/html
.
你看到它text/plain
不是text/html
.
The file in question was this one:
有问题的文件是这个:
https://raw.github.com/LPology/Bootstrap-IE7Fix/master/css/bootstrap-ie7fix.css
https://raw.github.com/LPology/Bootstrap-IE7Fix/master/css/bootstrap-ie7fix.css
What I did in Visual Studio 2013 Ultimate was:
我在 Visual Studio 2013 Ultimate 中所做的是:
- Right-clicked the project's
Content
folder and selected AddStyle Sheet
. - Renamed the file to
bootstrap-ie7fix.css
- Copied the full content of the above
.css
file - Pasted the entire content inside Visual Studio and saved the file
- 右键单击项目的
Content
文件夹并选择 AddStyle Sheet
。 - 将文件重命名为
bootstrap-ie7fix.css
- 复制上述
.css
文件的全部内容 - 将整个内容粘贴到 Visual Studio 中并保存文件
Referenced this new file in my Razor
view in an ASP.NET MVC
app in the exactly same old default fashioned accepted way:
在我Razor
的ASP.NET MVC
应用程序中以完全相同的旧默认接受方式在我的视图中引用了这个新文件:
<link rel="stylesheet" type="text/css" href="/../itvizionlogs/widgets/Content/bootstrap-ie7fix.css">
For any crazy/unknown reason that file would show nothing in Chrome, Firefox, Internet Explorer. What the hell is going on with this file since all other ones in the exact same /Content
directory are loading just fine?
由于任何疯狂/未知的原因,该文件在 Chrome、Firefox、Internet Explorer 中不会显示任何内容。这个文件到底是怎么回事,因为完全相同/Content
目录中的所有其他文件都加载得很好?
My last try was this:
我最后一次尝试是这样的:
- Navigated to the original file in the browser: https://raw.github.com/LPology/Bootstrap-IE7Fix/master/css/bootstrap-ie7fix.css
- Clicked Chrome's
File => Save Page As...
menu option and overwrote the existing file in my /Content dir. - Tried reloading my app page and voila... this mysterious .css file finally got loaded.
- 在浏览器中导航到原始文件:https: //raw.github.com/LPology/Bootstrap-IE7Fix/master/css/bootstrap-ie7fix.css
- 单击 Chrome 的
File => Save Page As...
菜单选项并覆盖我的 /Content 目录中的现有文件。 - 尝试重新加载我的应用程序页面,瞧……这个神秘的 .css 文件终于被加载了。
I guess Visual Studio scrambled the encoding of that file initially or something like that!
我猜 Visual Studio 最初扰乱了该文件的编码或类似的东西!
回答by xuxiaojian
I don't know whether you developed your project in the framework. i had this mistakes ,when i developed in the ThinkPHP Framework. And the reason is that the frameowrk has some rules about the path of the css file to be include so that if you use the framework ,you can check out whether the framework has its rules for the path of outside css file or javascript file.
不知道你的项目是不是在框架中开发的。当我在 ThinkPHP 框架中开发时,我遇到了这个错误。原因是frameowrk对要包含的css文件的路径有一些规则,所以如果你使用框架,你可以检查框架是否有关于外部css文件或javascript文件路径的规则。
回答by Helzgate
I had this using webpack-dev-server, it was because of a firewall issue blocking internet access. I initially didn't think it was internet related because I thought I bundled all of my css without depending on external sources. But after digging, I found another css file that was trying to load external fonts from fonts.gstatic.com, this along with my firewall, created my issue.
我使用 webpack-dev-server 进行了此操作,这是因为防火墙问题阻止了 Internet 访问。我最初不认为它与 Internet 相关,因为我认为我捆绑了所有的 css,而不依赖于外部资源。但是在挖掘之后,我发现另一个 css 文件试图从 fonts.gstatic.com 加载外部字体,这与我的防火墙一起造成了我的问题。