Saturday, 15 May 2010

How do you enable cross-origin requests (CORS) in ASP.NET 5 & MVC 6? -


I want to enable the Corus on an API created with MVC 6, but all the current documents are available in the earlier versions of that framework Look at

Notes on new cos features are very light, but I was able to work in new classes and Looking at the ways my solution looks like my web API startup.cs you can see how you can build your own basics and policies using the new CorsPolicy class Are you Enabling CORS with and AddCors and UseCors methods.

Public Zero Configuration Services (services); services.AddMvc (); // Add service support for service services. Edcore (); Var Policy = New Microsoft.AspNet.Cors.Core.CorsPolicy (); Policy.Headers.Add ("*"); Policy.Methods.Add ("*"); Policy.Origins.Add ("*"); Policy.SupportsCredentials = True; Services.ConfigureCors (x => x.AddPolicy ("mypolicy", Policy)); } Configure Public Zero (IApplicationBuilder app, IHostingEnvironment env) {// HTTP Request Configure pipeline app.UseStaticFiles (); // Use the new policy in global policy. Euskers ("mipolysis"); // Add MVC to the request pipeline. App.UseMvc (); } You can also refer to the policy in controllers, such as with new properties <[EnableCors ("mypolicy")] [root (" API / [Controller] ")]

No comments:

Post a Comment