[英]Thread.CurrentPrincipal has null details on Azure
我們正在嘗試使用Thred.CurrentPrincipal來獲取用戶信息。 但是,一旦將其部署到Azure,CurrentPrincipal就為空。
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);
}
我確認ADFS設置正確。 如果有人可以指出我的痛苦點,那就太好了。
編輯:
CurrentPrincipal不是NULL,但詳細信息是。 因此,我們沒有得到用戶的姓名,角色和其他詳細信息。
編輯2:
這是在Azure上發生的事情:
您可能需要打開“用戶配置文件”才能使主體工作。
啟用它在您網站的門戶中,轉到“配置”->“應用程序設置”,然后添加應用程序設置WEBSITE_LOAD_USER_PROFILE =1。您的網站必須處於“基本”或“標准”模式才能正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.