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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With