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

末鹿安然 提交于 2019-12-07 04:11:44

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/46528292/asp-net-core-iis-hosting-user-identity-name-is-empty-and-isauthenticated-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!