1. 背景
在springboot项目中前后端建立websocket连接,页面会报错!!!
2.异常信息
这个会导致使用iframe模式上传图片或者iframe嵌套页面时,会报如下异常信息:
Refused to display in a frame because it set ‘X-Frame-Options’ to ‘DENY’
3. 解决方法
拓展WebSecurityConfigurerAdapter的配置
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http
...
.headers().frameOptions().disable()//防止iframe
.and()
...
}
}
增加http.headers().frameOptions().disable();这个配置后,响应头中就找不到这个配置了。