Sorry, not sure which forum this question fall into. If anyone knows then please suggest so I will ask in respective forum.
I have a web api and a web site developed on ASP.NET Core (VS 2017). The website works well on localhost and is able to call the web api and get returns. Also deployed
website on my AZURE Development VM (Windows server 2016 ) IIS 10.0.
and is able to call the web api and get returns.
Both of the sites were then deployed to Windows Server 2008 R2, running on IIS 7. I have followed numerous articles on how to configure IIS for ASP.NET Core and I am satisfied
that the configuration is right (As it is working fine into Windows server 2016).
I can browse to both URLs and nothing is failing. However, when the website call the web api I get Error 401: UnAuthorised
Has anyone experienced this and can some recommend a solution.
What I have tried:
I tried using Postman to see if I can reach the API and return some values, the calls were successful and returned the requested data.
I looked at the permissions on the folder and on the site of the web api site. Everything looks normal (as it should be)
Technology and configuration- Website and API both on .Net Core 2.2 and MVC
- Both configured for Windows Authentication
- API controller has attribute [Authorize] (I have tried removing this attribute but no luck)
- Both deployed on IIS 7 of Server 2008 R2
- Both runs as Hosted=InProcess
- Both has its own App Pool using "no managed" and Classic mode (As per MSDN Document)
MVC Website Startup.cs code
Method: ConfigureServices
services.AddHttpClient("MyAPI", client =>
{
client.BaseAddress = new Uri(baseUrl);
client.Timeout = new TimeSpan(0,0,0,60);
})
.ConfigurePrimaryHttpMessageHandler(
handler => new HttpClientHandler
{
Credentials = CredentialCache.DefaultNetworkCredentials
,AllowAutoRedirect = false
//,UseDefaultCredentials = true
}
)
;
Method: Configure
app.UseCookiePolicy();
app.UseCors(c => c
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
);
app.UseAuthentication();
// Set routing rules
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=api}/{action=Index}/{id?}");
});
Praitk