.net - Web API.. 401 (Unauthorized) Chrome CORS -




i have 2 sites running. classic webapi server , angular4 client. have cors working on server. know cors not work chrome unless start chrome security off localhost. , when works fine.

but understood when moved off localhost site (the site use port number. looks http://mytest:8080/info) chrome work fine. have same problem 401 (unauthorized).

it works on ie no problem , if run chrome security off works well.

update:

fixed this:

on server did custom headers (in web.config)

<customheaders>           <add name="access-control-allow-headers" value="x-aspnet-version,x-powered-by,date,server,accept,accept-encoding,accept-language,cache-control,connection,content-length,content-type,host,origin,pragma,referer,user-agent" />           <add name="access-control-allow-methods" value="get,post,put,delete,options" />           <add name="access-control-allow-credentials" value="true" />       </customheaders> 

in global.aspx.cs have

 public static void register(httpconfiguration config)     {        config.maphttpattributeroutes();       var corsattr = new enablecorsattribute("http://{serveraddress}:8420", "*", "*");       config.enablecors(corsattr);        config.routes.maphttproute(           name: "defaultapi",           routetemplate: "api/{controller}/{id}",           defaults: new { id = routeparameter.optional }       );     } 

and on client site did call like

var options = new requestoptions({         headers: new headers({             'accept': 'application/json',         }),         withcredentials: true     });     return this.http.get(this.apiaddress + '/api/user', options)         .map(res => res.json() user); } 

the answer above under fixed.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -