Asp.Net WebApi2 Enable CORS not working with AspNet.WebApi.Cors 5.2.3

后端 未结 11 520
庸人自扰
庸人自扰 2020-11-27 11:06

I tried to follow the steps at http://enable-cors.org/server_aspnet.html to have my RESTful API (implemented with ASP.NET WebAPI2) work with cross origin requests (CORS Enab

11条回答
  •  遥遥无期
    2020-11-27 11:43

    No-one of safe solution work for me so to be safer than Neeraj and easier than Matthew just add: System.Web.HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

    In your controller's method. That work for me.

    public IHttpActionResult Get()
    {
        System.Web.HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
        return Ok("value");
    }
    

提交回复
热议问题