I am trying to add the X-Frame-Options header (with value set to "DENY") into my MVC 4 application. I looked around and it seems this is the cleanest way to add for all pages.
However when I add this code it will not build. With an error on OnResultExecuting
of
"no suitable method found to override."
public class XframeOptions : ActionFilterAttribute
{
public override void OnResultExecuting(
System.Web.Mvc.ResultExecutingContext filterContext)
{
filterContext.HttpContext.Response.AddHeader(
"X-Frame-Options", "DENY");
}
}
If this is the cleanest way to do this how can I resolve this error? Is there a better way to handle this in an MVC 4 application?