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

1

6

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?

Swinge answered 2/10, 2017 at 15:6 Comment(0)
S
2

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://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware

Swinge answered 3/10, 2017 at 6:41 Comment(1)
This answer would be a lot more valuable if there were a few extra details provided, as opposed to just article links.Twice

© 2022 - 2024 — McMap. All rights reserved.