I have problem for hosting CORS enabled ASP.NET (2.1) Web API hosted via IIS 8.5 running in 2012 R2. I have enabled CORS in my Web API configuration with the following code:
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
When running on dev machine with IIS express, angular.js client can call web api correctly. The browser first sends OPTIONS and then GET, POST, PUT or DELETE. No any problem with that.
Then I created new web site into IIS 8.5 and deployed my web api application into that. First I encounterd the problem that browser received HTTP 405 for every OPTIONS request. Ok, I enabled OPTIONSVerbHandler for my site and browser started to receive 200 OK. However it misses all the needed CORS headers. That I can overcome by manually adding custom headers into each web request.
It makes me wonder that why I need to define CORS settings in different places; web api application, handler mapping and custom headers. Or am I doing something wrong here?