I followed the aspnet site tutorial to enable cors and i cant get it working.
Register method on WebApiConfig:
public static void Register(HttpConfiguration config)
{
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
config.MapHttpAttributeRoutes();
}
Controller:
public class TestController : Controller
{
[Route("test/{*anything}")]
public ActionResult Index()
{
return Json(new { test = "test message" },
JsonRequestBehavior.AllowGet);
}
}
Then i create a simple website with a minimum index.html served by the nodejs live-server making an ajax request and it works ok when debuggin locally. But when i publish it to azure i get the following error :
XMLHttpRequest cannot load http://mysite.azurewebsites.net . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access
EDIT:
I have installed the Microsoft.AspNet.WebApi.Cors version 5.2.3
Seems like you are using MVC Controller instead of Api Controller (unless its DotNet Core). Change the Base class to ApiController with action return type IHttpResponseMessage and return Ok (new { test = "test message" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With