简体   繁体   中英

How to change X-Frame-Options" from DENY to SAMEORIGIN

I'm working with ASP.NET. Due to security reasons I hadto set X-Frame-Options to DENY in Web.Config. But the site contains some iframes. So, I have to change the X-Frame-Options to SAMEORIGIN from time to time.

In the Page_PreRender event I have written the following code:

HttpContext.Current.Response.Headers.Remove("X-Frame-Options");
HttpContext.Current.Response.AppendHeader("X-Frame-Options", "SAMEORIGIN");
```

But I still get the DENY option from the web config.

Please, any ideas?

Have a look at this answer: https://stackoverflow.com/a/42168501/970074

Depending on your project, you'll likely want to look at another location to insert the "DENY" instead of in the web.config so that you can override it when necessary with "SAMEORIGIN". Action filters would be a good place to do this if you're using MVC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM