我有这个问题。Chrome继续返回此错误
资源解释为样式表,但以MIME类型text/html传输
受此错误影响的文件只有Style、chosen和jquery-gentleselect(以相同方式导入索引的其他CSS文件工作良好且没有错误)。我已经检查了我的MIME类型和文本/css已经在css上。
老实说,我想从理解问题开始(这似乎是我一个人做不到的事情)。
我有这个问题。Chrome继续返回此错误
资源解释为样式表,但以MIME类型text/html传输
受此错误影响的文件只有Style、chosen和jquery-gentleselect(以相同方式导入索引的其他CSS文件工作良好且没有错误)。我已经检查了我的MIME类型和文本/css已经在css上。
老实说,我想从理解问题开始(这似乎是我一个人做不到的事情)。
当前回答
@Rob Sedgwick的回答给了我一个指针,然而,在我的情况下,我的应用程序是一个春季启动应用程序。所以我只是在我的安全配置中为相关文件的路径添加了排除…
说明—此解决方案基于springboot…你需要做的可能会根据你使用的编程语言和/或你使用的框架而有所不同
然而,要注意的一点是;
从本质上讲,当每个请求,包括 那些静态内容正在被验证。
所以让我们说一些路径到我的静态内容,导致错误如下;
一个叫做“插件”的路径
http://localhost:8080/plugins/styles/css/file-1.css http://localhost:8080/plugins/styles/css/file-2.css http://localhost:8080/plugins/js/script-file.js
还有一个路径叫做pages
http://localhost:8080/pages/styles/css/style-1.css http://localhost:8080/pages/styles/css/style-2.css http://localhost:8080/pages/js/scripts.js
然后,我只需在Spring Boot安全配置中添加如下排除项;
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers(<comma separated list of other permitted paths>, "/plugins/**", "/pages/**").permitAll()
// other antMatchers can follow here
}
}
从身份验证中排除这些路径“/plugins/**”和“/pages/**”可以消除错误。
干杯!
其他回答
我有同样的问题,几分钟后,我破译,我错过了添加文件扩展名到我的头。所以我改了下面这行:
<link uic-remove rel="stylesheet" href="css/bahblahblah">
to
<link uic-remove rel="stylesheet" href="css/bahblahblah.css">
In my case, same error was coming with JSP. This is how I got to the root of this issue: I went to the Network tab and clearly saw that the browser request to fetch the css was returning response header having "Content-type" : "text/html". I opened another tab and manually hit the request to fetch the css. It ended up returning a html log in form. Turns out that my web application had a url mapping for path = / Tomcat servlet entry : (@WebServlet({ "/, /index", }). So, any unmatching request URLs were somehow being matched to / and the corresponding servlet was returning a Log in html form. I fixed it by removing the mapping to /
此外,tomcat配置wrt处理css MIME-TYPE已经存在。
我想扩展Todd R在op中的观点。在asp.net页面中,web。配置文件定义访问应用程序中每个文件或文件夹所需的权限。在我们的例子中,CSS文件文件夹不允许未经授权的用户访问,导致它在用户获得授权之前在登录页面上失败。更改web中所需的权限。通过修改CSS文件配置,可以防止非法用户访问CSS文件,解决了这一问题。
我的问题比这篇文章中的所有答案都要简单。
我必须设置IIS以包含静态内容。
如果你在prod中提供应用程序,请确保你在service worker中提供静态文件。当我在Django上只提供React构建的静态子文件夹时,我遇到了这个错误(没有具有样式的资产)