P3P Header Info in MVC

后端 未结 3 844
执笔经年
执笔经年 2021-01-02 12:58

I\'m not sure where I\'m suppose to put this in my Asp.net MVC website:

HttpContext.Current.Response.AppendHeader(\"P3P\", \"CP=\\\\\\\"IDC DSP COR ADM DEVi          


        
相关标签:
3条回答
  • 2021-01-02 13:39

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

    Then, add it to the global filters collection.

    0 讨论(0)
  • 2021-01-02 13:49

    Assuming you want this header on every response, 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());
        }
    
    0 讨论(0)
  • 2021-01-02 13:52

    You can put it in the web.config:

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

    This way you do not need to put it in the code.

    See this SO answer for details on what the value means.

    0 讨论(0)
提交回复
热议问题