Public Static classWebapiconfig { Public Static voidRegister (httpconfiguration config) {varsetting =System.Configuration.ConfigurationManager.AppSettings; varCors =NewEnablecorsattribute ("http://192.168.3.15:3000,http://192.168.3.15:3002","*","get,post,put,delete,options") {supportscredentials=true }; Config. Enablecors (cors); //Web API RoutingCONFIG. Maphttpattributeroutes (); Config. Routes.maphttproute (Name:"Defaultapi", Routetemplate:"api/{controller}/", defaults:New{id = routeparameter.optional}, Constraints:New{id =@"\d+" } ); } }
Or, however, you cannot configure multiple IP addresses in config
<system.webserver> <Httpprotocol> <customheaders> <Addname= "Access-control-allow-origin"value= "http://192.168.6.43:3000" /> <Addname= "Access-control-allow-headers"value= "X-requested-with,content-type" /> <Addname= "Access-control-allow-method"value= "Get,post,options" /> <Addname= "Access-control-allow-credentials"value= "true" /> </customheaders> </Httpprotocol> </system.webserver>
Webapi table header set cross-domain