Angular 7 app getting CORS error from angular client

后端 未结 7 2143
逝去的感伤
逝去的感伤 2020-12-15 21:36

I have developed an angular 7 app with express backend. Express running on localhost:3000 and angular client is running on localhost:4200.

In the

7条回答
  •  孤城傲影
    2020-12-15 22:02

    I have been working with Angular cli and .net Framework in server side.

    To solve this problem, I just ennable CORS interaction in server side using the following steps:

    1. Install-Package Microsoft.AspNet.WebApi.Cors -Version 5.2.6

      And then, into WebApiConfig class:

    2. Add using System.Web.Http.Cors;

    3. Inside Register(HttpConfiguration config) method:

    var cors = new EnableCorsAttribute("http://localhost:4200", "*", "*");
    
    config.EnableCors(cors);
    

    or

    var cors = new EnableCorsAttribute("*", "*", "*"); //origin, headers, methods
    
    config.EnableCors(cors);
    

提交回复
热议问题