c# - AngularJS request to ASP.NET Web API 2 CORS errors -


i have set ionic framework app (running in chrome browser) , asp.net web api 2 project. have token acquisition working /token, can no longer register.

i trying make request web api controller following error:

xmlhttprequest cannot load http://[web api 2 project]/api/values. no 'access-control-allow-origin' header present on requested resource. origin 'http://[ionic framework app]' therefore not allowed access. response had http status code 500. 

i have set startup.cs file such:

public partial class startup {     public void configuration(iappbuilder app)     {         app.usecors(microsoft.owin.cors.corsoptions.allowall);         configureauth(app);     } } 

i have set webapiconfig.cs such:

 public static class webapiconfig     {         public static void register(httpconfiguration config)         {             // web api configuration , services             // configure web api use bearer token authentication.             config.suppressdefaulthostauthentication();             config.filters.add(new hostauthenticationfilter(oauthdefaults.authenticationtype));              config.enablecors(new enablecorsattribute("*", "*", "*"));                // web api routes             config.maphttpattributeroutes();              config.routes.maphttproute(                 name: "defaultapi",                 routetemplate: "api/{controller}/{id}",                 defaults: new { id = routeparameter.optional }             );         }     } 

i have tried using web.config set access-control-allow-origin caused lot of more issues , seemed wasn't right way go. there else missing?


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -