【开发心得】解决iframe 请求security出现X-Frame-Options
  OIW0KlaMcRRl 2023年11月28日 77 0


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

报错截图:

【开发心得】解决iframe 请求security出现X-Frame-Options_无法显示

打开页面工具看到提示

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内容无法显示,解决问题!
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月28日 0

暂无评论

推荐阅读
  tqf4faUYHHCA   2023年12月23日   80   0   0 sedpythonPythonsed
OIW0KlaMcRRl