我有这个问题。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/**”可以消除错误。
干杯!
其他回答
我在为一个用npm安装的React布局模块加载CSS时遇到了这个问题。你必须导入两个.css文件来让这个模块运行,所以我最初导入它们是这样的:
@import "../../../../node_modules/react-grid-layout/css/styles.css";
但发现文件扩展名必须被删除,所以这是有效的:
@import "../../../../node_modules/react-grid-layout/css/styles";
我在MVC4中使用表单身份验证时遇到了类似的问题。问题出在web。config中的这一行,
<modules runAllManagedModulesForAllRequests="true">
这意味着每个请求,包括静态内容的请求,都要经过身份验证。
将这一行更改为:
<modules runAllManagedModulesForAllRequests="false">
I faced the same issue while configuring Postfix Admin 3.2. According to the official documentation, the whole Postfix Admin content should be extracted into a separate directory, i.e. /srv/postfixadmin and not the document root. Only the /srv/postfixadmin/public directory should be symlinked into /var/www/html document root. I have just extracted the whole content into /var/www/html. Having played with Nginx server block settings, I managed example.com/postfixadmin resolving from /var/www/html/postfixadmin/public. Nevertheless, images and CSS were not available with 404 status code. The stylesheets were broken. I got the error message OP quoted with respective 404 entries in access log.
在我的情况下,我只是移动/var/www/html/postfixadmin到/srv/postfixadmin和ln -s /srv/postfixadmin/公共/var/www/html/postfixadmin。这完全解决了问题。 这是参考资料。
使用角?
这是一个需要记住的非常重要的警告。
基本标签不仅要在头部,而且要在正确的位置。
我有我的基础标签在错误的地方在头部,它应该来之前任何标签与url请求。基本上把它作为标题下面的第二个标签为我解决了这个问题。
<base href="/">
我在这里写了一篇小文章
使用角
在我的情况下,使用ng-href而不是href解决了这个问题。
注意:
我和laravel一起做后台