Our site is not currently safe from clickjacking, so I went into the web.config and added
<system.webServer> <httpProtocol> <customHeaders> <add name="X-Frame-Options" value="DENY" /> </customHeaders> </httpProtocol> </system.webServer>
This is very straight forward code. My issue is that it's just not working. The questions I have are:
X-Frame-Options
is in the header response? I looked for it with httpfox and got nothing, so I can't verify if the web.config
is actually putting things in the header.I did try to add it in the Global.asax in the Application_Start
method, but I cant seem to "hit" this method when I debug; it does not hit breakpoints.
private void Application_Start(object sender, EventArgs e) { // Code that runs on application startup HttpContext.Current.Response.AddHeader("x-frame-options", "DENY"); LogHelper.Info("Cost of Care Web Application Starting"); }
I would like to add that I have tried to add it straight into the head tag and I've also tried to add it in a meta tag like so
<meta http-equiv="X-Frame-Options" content="deny">
Open Internet Information Services (IIS) Manager. In the Connections pane on the left side, expand the Sites folder, and select the site where you made this change. In the feature list in the middle, double-click the HTTP Response Headers icon. In the list of headers that appears, select X-Frame-Options.
The X-Frame-Options header can be used to control whether a page can be placed in an IFRAME. Because the Framesniffing technique relies on being able to place the victim site in an IFRAME, a web application can protect itself by sending an appropriate X-Frame-Options header.
To configure IIS to add an X-Frame-Options header to all responses for a given site, follow these steps:
HTTP Response Headers
icon in the feature list in the middle. X-Frame-Options
in the Name field and type SAMEORIGIN
or DENY
in the Value field. Since my comments answered the question here's the end result:
For some reason setting the X-Frame-Options
in web.config doesn't seem to actually work even though the documentation makes it sound like it should.
An easy work around is to set the headers manually using:
Response.AddHeader("X-Frame-Options", "DENY");
If you need this set for every request with no exceptions you can add the Application_BeginRequest
to Global.asax:
protected void Application_BeginRequest() { Response.AddHeader("X-Frame-Options", "DENY"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With