jquery - How to set up CORS properly on IIS? -


i've started working on phonegap mobile application authenticate , work asp.net webapi web services. 1 of issues on enable cors in iis using setting in web.config:

<system.webserver> <httpprotocol>   <customheaders>     <add name="access-control-allow-origin" value="*" />   </customheaders> </httpprotocol> 

this setting in part of .net webapi application. looking @ above, appears opens access control absolutely everyone, i'm not sure else possibly go value portion of header. mobile apps (html, javascript, etc) on mobile devices, making jquery calls api on server.

my api / html seem work expected above setting in place. if remove it, cors errors. above normal, or should more specific?

hi try put code webapiconfig below code

 public static class webapiconfig     {         public static void register(httpconfiguration config)         {             config.routes.maphttproute(                 name: "defaultapi",                 routetemplate: "api/{controller}/{action}/{id}",                 defaults: new { id = routeparameter.optional }             );             config.enablecors(new enablecorsattribute("*", "*", "*"));         } } 

by way have download "microsoft.aspnet.webapi.cors" enablecors nuget


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -