Sunday, November 12, 2017

opening up CORS in a .NET Core MVC project

As suggested here, it is different than what is here. Follow these steps:

  1. Install CORS with this NuGet command:
    install-package Microsoft.AspNetCore.Cors
     
  2. services.AddCors();
    ...goes in the ConfigureServices method of Startup.cs just before...
    services.AddMvc();
     
  3. app.UseCors(builder =>
          builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

    ...goes in the Configure method of Startup.cs just before...
    app.UseMvc();

 
 

I have, this weekend, made a dummy Hello World project that shows off Angular 4 and .NET Core 2.0 playing nicely together complete with tests on both sides of the wire and IoC on both sides of the wire. If you'd like to take a look you may see it here. The CORS thing is one of many challenges I fought with to make this happen.

No comments:

Post a Comment