I have a controller created with the default WebApi template. It creates one post method like this:
// POST: api/PedidosVenta
[HttpPost]
[ResponseType(typeof(PedidoVentaDTO))]
public async Task<IHttpActionResult> PostPedidoVenta(PedidoVentaDTO pedido)
At this time CORS was working fine from my computer and from different domains. Then I needed a second post method with a different route and I created it this way:
[HttpPost]
[EnableCors(origins: "*", headers: "*", methods: "POST")]
[Route("api/PedidosVenta/SePuedeServirPorAgencia")]
public async Task<RespuestaAgencia> SePuedeServirPorAgencia(PedidoVentaDTO pedido)
It works fine in my computer, even when I call this method, but when I try to run from a different domain, it throws CORS errors (only when I call this method, all the other ones work fine).
I am not able to solve it, so I am sure I am missing something important. Can anyone help me to config cors properly in this method, please?
Thank you
UPDATE: I paste the code of WebApiConfig:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize;
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
var cors = new System.Web.Http.Cors.EnableCorsAttribute(
origins: "*",
headers: "*",
methods: "*");
config.EnableCors(cors);
GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
}
}