c# web api 跨域问题

2021-03-01 15:27

阅读:488

标签:text   nta   content   api   status   object   end   toc   global   

 

webconfig 中增加配置:

 

"Access-Control-Allow-Origin" value="*" />
"Access-Control-Allow-Headers" value="Origin,X-Requested-With,Content-Type,accept,key" />
"Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />

 

Global.asax.cs文件中增加对于options支持

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var req = System.Web.HttpContext.Current.Request;
            if (req.HttpMethod == "OPTIONS")//过滤options请求,用于js跨域
            {
                Response.StatusCode = 200;
                Response.SubStatusCode = 200;
                Response.End();
            }
        }

 

c# web api 跨域问题

标签:text   nta   content   api   status   object   end   toc   global   

原文地址:https://www.cnblogs.com/bleychen/p/14318872.html


评论


亲,登录后才可以留言!