简体   繁体   中英

Thread.CurrentPrincipal has null details on Azure

We are trying to use Thred.CurrentPrincipal to get the user information. However as soon as we deploy it to Azure the CurrentPrincipal is null.

var td = new TokenData();

var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;

if (claimsPrincipal != null)
{
    td.IsAuthenticated = claimsPrincipal.Identity.IsAuthenticated;

    td.Name = claimsPrincipal.FindFirst(ClaimTypes.Name).Value;
    td.Email = claimsPrincipal.FindFirst(ClaimTypes.Upn).Value;
    td.Surname = claimsPrincipal.FindFirst(ClaimTypes.Surname).Value;
    td.Role = claimsPrincipal.FindAll("http://schemas.xmlsoap.org/claims/Group")
        .Select(s=>s.Value);
}

I verified that ADFS is set-up correctly. It would be great if someone could point me to the pain-point of this.

Edit:

The CurrentPrincipal is not NULL but the details are. So we are not getting the user's name, roles and other details.

Edit 2:

This is what is happening on Azure:

在Azure上进行远程调试

在Azure上进行远程调试

You might need to turn on User Profiles in order to get your principal to work.

To turn it on In the portal on your website go to Configuration -> App Settings and add the app setting WEBSITE_LOAD_USER_PROFILE = 1. You site needs to be in Basic or Standard mode for this to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM