Advertisement
hubert17

Enable Cross-origin Resource Sharing (CORS) in ASP.NET Core

Dec 16th, 2017
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | None | 0 0
  1. services.AddMvc();
  2. services.AddCors(
  3.     options => options.AddPolicy("AllowCors",
  4.     builder =>
  5.     {
  6.       builder
  7.       .AllowAnyOrigin() //AllowAllOrigins;
  8.       .AllowAnyMethod() //AllowAllMethods;
  9.       .AllowAnyHeader(); //AllowAllHeaders;
  10.     })
  11. );
  12.  
  13.       //Enable CORS policy "AllowCors"
  14.       app.UseCors("AllowCors");
  15.       app.UseMvc();
  16.  
  17.     [EnableCors("AllowCors")]
  18.     [Route("api/Songs")]
  19.     public class SongsController : Controller
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement