资源解释为样式表,但在 ASP.NET IIS 中使用 MIME 类型 text/html 进行传输
我有一个登录页面,执行时该页面被从 css
中剥离。
我从 chrome 调试器中发现了这条消息。我正在使用 asp.net 2008。
有什么想法吗?
<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>
根据@robx的建议进行编辑。
i am having a login page when executed the page is stripped out of css
.
I found out this message from from chrome debugger. I am using 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在我看来,问题出在您的 IIS 配置中。它可能被配置为传递具有 text/html MIME 类型的 .css 文件。
尝试转到 Web 服务器上的 MIME 类型配置,看看是否可以发现其中的任何内容。
.css 文件的正确 MIME 类型是 text/css。
您还可以使用一些 HTTP 嗅探器(例如 fiddler)查看 HTTP 标头参数。
更新:接受的答案应该是@brett-pennings 指出的答案!
只需提供静态内容,错误就会自动消失。
Seems to me like the problem is in your IIS configuration. it might be configured to deliver .css files with text/html MIME type.
Try going to the MIME types configuration on the web server and see if you can spot anything there.
The correct MIME type for .css files is text/css.
You can also have a look on the HTTP header parameters with some HTTP sniffer such as fiddler.
Updating: The accepted answer should be the one pointed by @brett-pennings!
Just providing static contents, the error vanished automatically.
确保在 IIS Windows 功能中启用“静态内容”。
Make sure you enable "Static Content" in IIS Windows Features.
当您在 IIS 中使用重写 url 时,这是一个问题(在我的例子中就是这样),您需要在重写条目之前在您的 web.config 文件中添加此条目,如下所示:
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:
哦亲爱的主啊!这是那些似乎不知从何而来的错误之一...我花了近 1 个小时的时间试图找出导致 1 个特定
.css
文件显示一条非常相似的消息的原因Chrome 的控制台窗口:您会看到它是
text/plain
而不是text/html
。有问题的文件是这个:
https:// raw.github.com/LPology/Bootstrap-IE7Fix/master/css/bootstrap-ie7fix.css
我在 Visual Studio 2013 Ultimate 中所做的是:
Content
文件夹并选择添加样式表
。bootstrap-ie7fix.css
.css
文件的完整内容在我的文件中引用这个新文件
ASP.NET MVC
应用程序中的Razor
视图采用完全相同的旧式默认接受方式:对于任何疯狂的人/该文件的未知原因在 Chrome、Firefox、Internet Explorer 中不显示任何内容。既然完全相同的
/Content
目录中的所有其他文件都加载得很好,那么这个文件到底是怎么回事?我的最后一次尝试是这样的:
https://raw.github.com/LPology/ Bootstrap-IE7Fix/master/css/bootstrap-ie7fix.css
File =>;将页面另存为...
菜单选项并覆盖我的 /Content 目录中的现有文件。我猜 Visual Studio 最初扰乱了该文件的编码或类似的事情!
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:You see it's
text/plain
instead oftext/html
.The file in question was this one:
https://raw.github.com/LPology/Bootstrap-IE7Fix/master/css/bootstrap-ie7fix.css
What I did in Visual Studio 2013 Ultimate was:
Content
folder and selected AddStyle Sheet
.bootstrap-ie7fix.css
.css
fileReferenced this new file in my
Razor
view in anASP.NET MVC
app in the exactly same old default fashioned accepted way: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?My last try was this:
https://raw.github.com/LPology/Bootstrap-IE7Fix/master/css/bootstrap-ie7fix.css
File => Save Page As...
menu option and overwrote the existing file in my /Content dir.I guess Visual Studio scrambled the encoding of that file initially or something like that!
不知道你的项目是否是在框架中开发的。
当我在ThinkPHP框架中开发时,我遇到了这个错误。
原因是frameowrk对要包含的css文件的路径有一些规则,因此如果您使用该框架,您可以检查框架是否对外部css文件或javascript文件的路径有其规则。
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.
我使用 webpack-dev-server 遇到了这个问题,这是因为防火墙问题阻止了互联网访问。我最初并不认为它与互联网相关,因为我认为我捆绑了所有的 css 而不依赖于外部资源。但经过挖掘,我发现另一个 css 文件试图从 fonts.gstatic.com 加载外部字体,这与我的防火墙一起创建了我的问题。
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.