Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP .NET Core IIS Hosting user identity name is empty and IsAuthenticated=false

I'm running ASP .NET Core dll on IIS (with AspNetCoreModule)

With previous ASP .NET I could get the user identity name with:

HttpContext.Current.User.Identity.Name

since it was called directly in IIS context.

With ASP .NET Core the result is null for:

this.Request.User.Identity.Name

It seems that IIS is not forwarding it or maybe my AspNetCore module doesn't receive it. How can I receive User Identity name?

like image 924
Danny Barack Avatar asked Oct 02 '17 15:10

Danny Barack


1 Answers

I solved the problem. This how I debugged it:

Since I was not sure if the user credentials are passed from the IIS, I decided to print out Request HTTP headers from the code to log file. The answer was there. I figured out that the IIS works with Basic Authentication.

It seems that Basic authentication is not supported in AspNetCore, so I added a middleware implementation that parse the information from the 'Authorization' header and create new user identity from it.

I made my own implementation but the following articles helped me a lot:

https://blog.dangl.me/archive/http-basic-authentication-in-aspnet-core-projects/

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware

like image 188
Danny Barack Avatar answered Oct 28 '22 21:10

Danny Barack