CORS support package not working in Web API 5.0.0-rc1

Topics: ASP.NET Web API
Sep 4, 2013 at 7:38 PM
Hello,

I have the latest WebAPI installed (v5.0.0-rc1) and have installed the latest CORS support package (v5.0.0-rc1).

GET works fine, but when sending POST, I always get:
OPTIONS http://localhost:19357/api/v1/rooms? 404 (Not Found) angular.js:10159
OPTIONS http://localhost:19357/api/v1/rooms? Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin. angular.js:10159
XMLHttpRequest cannot load http://localhost:19357/api/v1/rooms. Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.
When I check Fiddler, only the OPTIONS request is sent - not the POST.

Here is my Register() method in WebApiConfig.cs:
public static void Register(HttpConfiguration config)
{
    config.MapHttpAttributeRoutes();

    var cors = new EnableCorsAttribute("*", "*", "*");
    config.EnableCors(cors);
}
Because EnableCorsAttribute and EnableCors() are available, the package must be installed correctly.

I had a Web.config or a Application_BeginRequest() hack, but removed it in favor of this support package.

Anyone got a solution for me?
Sep 4, 2013 at 10:20 PM
Maybe you're hitting this issue with attribute routing?
The issue has been fixed recently so you won't have it in v5.0.0-rc1. But still, you can try out the nightly builds which will most certainly have the fix.

Hope this helps,
Yao
Sep 5, 2013 at 1:43 AM
Most definitely. Thank you for your answer! I'll try the nightly builds.
Sep 5, 2013 at 2:28 PM
Edited Sep 5, 2013 at 2:29 PM
One question, now when HttpGetAttribute/HttpPostAttribute/HttpPutAttribute/HttpDeleteAttribute no longer take parameters, what should I use instead? Do you have some instructions for the new usage?
Coordinator
Sep 5, 2013 at 2:48 PM
Use the new RouteAttribute.

You can also refer to the updated feature spec for attribute routing for details on other changes:

https://aspnetwebstack.codeplex.com/wikipage?title=Attribute%20routing%20in%20MVC%20and%20Web%20API&referringTitle=Specs

Daniel Roth
Sep 5, 2013 at 3:10 PM
Edited Sep 5, 2013 at 3:11 PM
Thank you.

I upgraded to 5.0.0-rtm-130905 and it's not fixed. I'm still getting:
XMLHttpRequest cannot load http://localhost:19357/api/v1/rooms/176?. Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin. localhost:8000/:1
XMLHttpRequest cannot load http://localhost:19357/api/v1/rooms/176/bookings?. Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.
My Register() in WebApiConfig.cs is the following:
public static void Register(HttpConfiguration config)
{
    config.MapHttpAttributeRoutes();

    var cors = new EnableCorsAttribute("*", "*", "*");
    config.EnableCors(cors);

    config.EnsureInitialized();
}
Developer
Sep 5, 2013 at 3:57 PM
Could you share a repro of this issue?

Sent from my Windows Phone

Sep 5, 2013 at 5:59 PM
Ok I confirm that this has been fixed in 5.0.0-rtm-130905. Sorry, my bad.