I modified a ASP.NET Web API 2 project to make use of Microsoft Azure Mobile Servies.
I'm developing a Phonegap app and testing it using my Desktop Chrome Browser and a locally running Azure Mobile Service.
Before I "converted" my project I handled CORS using this lines of code in my startup code (requires NuGet Package Microsoft.AspNet.WebApi.Cors):
#if DEBUG
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
#if DEBUG
config.MapHttpAttributeRoutes();
...
This worked like a charm, the required headers for Chrome have been written to the response without a problem.
Now using Azure Mobile Serives, the code looks like this:
public static void Register()
{
ConfigOptions options = new ConfigOptions();
HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));
#if DEBUG
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
#endif
}
Now my CORS setup does not work anymore, there are no headers present.
Adding the header in web.config works, but I would prefer programmatic approach.
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
...
Any ideas?