asp api接口支持跨域

来源:互联网 发布:如何加入网络作家协会 编辑:程序博客网 时间:2024/06/02 04:15
 #region 支持跨域请求
                    Response.ClearHeaders();
                    Response.AppendHeader("Access-Control-Allow-Origin", "*");//过滤头部
                    if (HttpContext.Current.Request.HttpMethod == "OPTIONS") // 支持post跨域
                    {
                        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
                        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept,X-Requested-With");
                    }
                    #endregion
阅读全文
0 0
原创粉丝点击