Im building some angular app that will use .net core webapi. it is working fine when i use enable anonymous authentication, but fails with windows authentication ;/ no mather if hosted in iis express or in full iis on windows server. also
i added cors policy to webapi , i added withCredentials : true to angular http call , added .AllowCredentials(); to api cors config still error ocurrs
the api call is fine when made from postman with NTLM authentication enabled and added my domain / user / pass into it
web api have:
public void ConfigureServices(IServiceCollection services)
{
string[] HostOrigins = new string[] { "http://localhost:4200", "https://localhost:4200" };
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", builder =>
{
builder.WithOrigins(HostOrigins)
.AllowAnyHeader().AllowAnyMethod().AllowCredentials();
});
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseCors("CorsPolicy");
app.UseHttpsRedirection();
app.UseMvc();
}
}
in angular service to do post request:
Post(endpoint: string, PostData: any, callbackF: ((data) => void) , errorF?: ((error) => void) )
{
return this.http.post(endpoint, PostData, { withCredentials : true })
.subscribe(
(data) => callbackF(data),
(error) => {
if (errorF) { errorF(error); }
else {
console.log('unCatch error:' + (JSON.stringify(error)));
}
}
);
and actual service call in angular component
this.DataService.Post('http://localhost:51500/sp/ApiTest',
{str1: 'asd', int1: '1', bit: 'false'},
(data: any) => {
console.log(JSON.stringify(data));
});
it fails with
unCatch error:{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":"http://localhost:51500/sp/ApiTest","ok":false,"name":"HttpErrorResponse","message":"Http failure response for http://localhost:51500/sp/ApiTest: 0 Unknown Error","error":{}}
HTTP401: ...
(XHR)OPTIONS — http://localhost:51500/sp/ApiTest
in firefox it also claims that it is same origin policy error but if it would be that - it should also fail when using anonymous auth? i known that firefox like to claim that 'other error' = 'cors error' ;)
please advaice if someone had problem like this
best regards !
edit
here is what i recive in postman - it means that it works but i see no cors header ? is it ok or it should be there ?