Posts

Showing posts with the label iframe

Working around X-Frame-Options for iframes

Image
The problem: One of the first things we noticed after migrating to SharePoint 2013 was that our iframes have stopped working, giving the error: "Refused to display 'http://contoso/pages/home.aspx' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'." Quickly we could see that this is in fact a security mechanism to prevent click-jacking and others: "The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a frame or iframe. Sites can use this to avoid Clickjacking attacks, by ensuring that their content is not embedded into other sites." Soon we realized that, starting SharePoint 2013, an HTTP Module is adding the header " X-Frame-Options " by default, with the value " SAMEORIGIN ". This is effectively preventing the rendering of pages outside the scope of the current web application. The (attempted) solution: So what to do?...

.Net FindControl - find your html controls

Sometimes the FindControl method won't find your control, if its on the masterpage or if its inside a contentplace holder. To fix this: ContentPlaceHolder cph = this.Form.FindControl("ContentPlaceHolder1") as ContentPlaceHolder; HtmlControl myFrame = (HtmlControl)cph.FindControl("iframe01"); myFrame.Attributes["src"] = url_geo; or HtmlControl myFrame = (HtmlControl)this.Master.FindControl("controlid"); Source: http://csharporcas.blogspot.com/2006/05/master-page-find-control.html P.S.: Your iframe may need the runat="server" tag for this to work!