【发布时间】:2020-01-30 01:08:33
【问题描述】:
我正在尝试构建一个 webapp 以部署在我们的 Intranet 上。我正处于我想要用户信息的阶段。
据我所知,我已经通过实施正确设置了身份验证:
在 Startup->ConfigureServices 中:
services.AddRazorPages();
services.AddAuthentication(IISDefaults.AuthenticationScheme);
并在启动->配置中:
app.UseAuthentication();
app.UseAuthorization();
现在在一个页面模型中,我一直在尝试获取用户信息,但似乎无法通过 userName 和 Groups。
public void OnGet()
{
var wi = (WindowsIdentity)User.Identity;
this.email = wi.Claims.FirstOrDefault(
c => c.Type == ClaimTypes.Email)?.Value;
this.claimsCount = wi.Claims.Count().ToString();
this.claims = wi.Claims.Select(x => x.Type.ToString()).ToList();
this.authenticationType= wi.AuthenticationType.ToString();
this.name = wi.Name;
if (wi.Groups != null)
foreach (var group in wi.Groups)
{
try
{
this.groups.Add(group.Translate(typeof(NTAccount)).ToString());
}
catch (Exception)
{
// ignored
}
}
}
这就是我在模型中得到的结果。
this.email = null
this.claimsCount = 51
this.claims = {A list composed of claims/name, claims/primarysid, claims/primarygroupsid, claims/groupsid x 48}
this.authenticationType = Negotiate
this.name = my login username
如何从这里获取用户的电子邮件地址和名字(即:“John Doe”而不是“CA/jdoe”)?我的研究使我相信我可能没有权限在我的本地计算机上获取此信息。
如果是这种情况,我该如何去检查部署服务器以查看它是否具有获取此信息所需的权限?
【问题讨论】:
标签: asp.net windows-authentication intranet