I am trying to enable CORS support in a Web API application. In my WebApiConfig.cs
file, I have the following code:
var cors = new EnableCorsAttribute(origins: "http://localhost:19509",
headers: "*",
methods: "*");
config.EnableCors(cors);
However, this didn't work. I've tried every suggestion from the following links, but they don't work either:
- Asp.net web API CORS series/mysterious issue
- MVC web api: No 'Access-Control-Allow-Origin' header is present on the requested resource
I created an empty project with no authorization/authentication/security implementation and tried hitting this empty project from my front end, and that worked. Based on this, I believe that the front end implementation is fine.
Is there a specific package which might be causing this issue, or anything else I need to change?
It runs when i try with a cors disabled Chrome browser.
//Updating the Question after implementing CORS in StartUp.cs file.
I tried applying cors in StartUp.cs file also but No luck. Below is my code in StartUp.cs file.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Abstractions;
using Microsoft.Owin;
using Owin;
using System.Web.Services;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.AspNetCore.Cors;
namespace xyz
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}