P3P Header Information in MVC

I'm not sure where I can post this on my MVC website on Asp.net:

HttpContext.Current.Response.AppendHeader("P3P", "CP=\\\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\\\""); 

I put it in:

 public static void RegisterRoutes(RouteCollection routes) { HttpContext.Current.Response.AppendHeader("P3P", "CP=\\\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\\\""); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Account", action = "Logon", id = UrlParameter.Optional } ); } 

But I'll be back

In this context, the answer is not available.

Does anyone know where I can put this?

+6
c # asp.net-mvc razor
Dec 20 '12 at 15:49
source share
3 answers

You can put it in the web.config file:

  <system.webServer> <httpProtocol> <customHeaders> <add name="P3P" value='CP="CAO PSA OUR"'/> 

Thus, you do not need to specify it in the code.

For more on what value means, see this SO answer .

+37
Dec 20 '12 at 15:52
source share

Assuming you want this header for each answer, something like this should do it

 public class P3PHeaderAttribute : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext filterContext) { filterContext.HttpContext.Response.AppendHeader("P3P", "CP=\\\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\\\""); } } 

then add the filter to the global collection

  public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new P3PHeaderAttribute()); } 
+5
Dec 20 '12 at 15:55
source share

You should create a class that inherits ActionFilter and overrides OnResultExecuting() to add this header.

Then add it to the global filter collection.

+1
Dec 20
source share



All Articles