Tuesday, December 2, 2014

Enabling CORS

I was reading up on Enabling Cross-Origin Requests in ASP.NET Web API 2 http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api. It really cool what the Web API is evolving in to. I wanted to test the EnableCors attribute on my controller and in my rash I did read the hole article. I just pasted [EnableCors(origins: "http://mywebclient.azurewebsites.net", headers: "*", methods: "*")] in to my code and redeploy my solution. But no good, I was getting an error. I spend over 5 min doing trial n error. I even try to change the web.config in hand, to se if my client code was broken. When back to the article, a bit mad and discovered I was missing this single line of code config.EnableCors(); in the WebApiConfig class.

So mental note, cross-origin-requests is now really nice to manage with EnableCors and always read the highlighted part of a technical article!

No comments:

Post a Comment