【开发心得】解决iframe 请求security出现X-Frame-Options

在开发SpringSecurity配置的项目时,返回带有iframe的页面时,无法显示。

报错截图:

打开页面工具看到提示

Refused to display in a frame because it set 'X-Frame-Options' to 'DENY'

>>>>> Springboot 2.x 要在继承了 WebSecurityConfigurerAdapter 的配置类中配置。

结合SpringBoot只要在页面访问控制的配置中加上

http
  .authorizeRequests().antMatchers("/login","/login-error","/401","/css/**","/js/**").permitAll()
  .and().formLogin().loginPage( "/login" ).failureUrl( "/login-error" ).successForwardUrl("/index")
  .and().headers().frameOptions().disable()//防止iframe内容无法显示
  .and().exceptionHandling().accessDeniedPage( "/401" )
  .and().authorizeRequests().anyRequest().authenticated();
插入.and().headers().frameOptions().disable()//防止iframe内容无法显示,解决问题!

posted @   虹梦未来  阅读(75)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
点击右上角即可分享
微信分享提示