如何使用C#代码从Windows Active Directory获取当前用户的登录名?
我正在UserPrincipal.Current.ToString()域中使用方法来获取具有有效域的域用户当前记录.但当我在一个字符串中显示它时,它在IIS服务器中托管时给出错误:
Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal'
to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.
Run Code Online (Sandbox Code Playgroud)