获取UPN或电子邮件进行登录的用户在.NET Web应用程序 [英] Get UPN or email for logged in user in a .NET web application
问题描述
我不是一个.NET开发人员,我有一种感觉,这将是微不足道的人谁是:
I'm not a .NET developer, and I have a feeling this would be trivial for someone who is:
我有一个C#的Web应用程序,使得已登录用户的用户凭据的用户。目前它使用它来自该SID
I have a C# web application that makes user of the user credentials of the logged in user. Currently it uses the SID which comes from
System.Security.Principal.WindowsIdentity.GetCurrent().User.Value
我需要得到的,而不是SID无论是用户UPN账号或电子邮件地址(如Active Directory中定义)。 GetCurrent()返回一个类型的WindowsIdentity的对象;看在细节的WindowsIdentity成员:
I need to get either the users UPN login or email address (as defined in active directory) instead of the SID. GetCurrent() returns an object of type WindowsIdentity; looking in the details for WindowsIdentity Members:
<一个href="http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity%5Fmembers.aspx">MSDN:的WindowsIdentity成员
我看不到任何东西,看起来像它会给我无论是UPN或电子邮件在那里。我怎么能拉起来的信息的使用,无论是喂SID转换成一些其他的功能,或调用的东西摆在首位的不同。
I can't see anything that looks like it would give me either the UPN or email in there. How can I pull up that information to use, either by feeding the SID into some other function or calling something different in the first place.
推荐答案
同时(.NET 3.5),这是一个班轮:
Meanwhile (.NET 3.5) this is a one-liner:
System.DirectoryServices.AccountManagement.UserPrincipal.Current.EmailAddress
有关的电子邮件,或
System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName
的UPN。
这篇关于获取UPN或电子邮件进行登录的用户在.NET Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!