adding header to http response in an action inside a controller in asp.net/mvc

前端 未结 5 2099
花落未央
花落未央 2021-02-13 18:14

I am streaming data from server to client for download using filestream.write. In that case what is happening is that I am able to download the file but it does not

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-13 18:44

    In the past I built a whitelist to allow some domains to iframe my site. Remember Google's image cache used to iframe sites as well.

    static HashSet frameWhiteList = new HashSet { "www.domain.com",
                                                        "mysub.domain.tld",
                                                        "partner.domain.tld" };
    
        protected void EnforceFrameSecurity()
        {
            var framer = Request.UrlReferrer;
            string frameOptionsValue = "SAMEORIGIN";
    
            if (framer != null)
            {
                if (frameWhiteList.Contains(framer.Host))
                {
                    frameOptionsValue = string.Format("ALLOW-FROM {0}", framer.Host);
                }
    
            }
    
            if (string.IsNullOrEmpty(HttpContext.Current.Response.Headers["X-FRAME-OPTIONS"]))
            {
                HttpContext.Current.Response.AppendHeader("X-FRAME-OPTIONS", frameOptionsValue);
            }
        }
    

提交回复
热议问题