CORS with WebAPI for XmlHttpRequest

前端 未结 5 809
不知归路
不知归路 2020-12-14 04:45

Just wanted to know what is the best elegant way (currently available) to handle CORS (Cross-Origin Resource Sharing) in ASP.NET WebAPI so i can use XmlHtt

5条回答
  •  Happy的楠姐
    2020-12-14 05:18

    There is now CORS support in the nightly of web api

    http://blogs.msdn.com/b/yaohuang1/archive/2013/04/05/try-out-asp.net-web-api-cors-support-using-the-nightly-builds.aspx

    Use nuget to:

    • Uninstall the Microsoft.AspNet.Mvc.FixedDisplayModes package.
    • Install Microsoft.AspNet.WebApi.Cors package from the nightly builds

    Then fix the bindings in the web.config Then enable CORS

    config.EnableCors(new EnableCorsAttribute()) 
    

    Read more about it on this wiki https://aspnetwebstack.codeplex.com/wikipage?title=CORS%20support%20for%20ASP.NET%20Web%20API&referringTitle=Specs

    Edit 19-04-2013 Scott Guthrie has blogged about it: http://weblogs.asp.net/scottgu/archive/2013/04/19/asp-net-web-api-cors-support-and-attribute-based-routing-improvements.aspx

提交回复
热议问题