C#Active Directory身份验证

本文关键字:身份验证 Directory C#Active | 更新日期: 2023-09-27 18:22:41

我在AngularJS中有一个重型客户端Web应用程序。我正在使用C#控制器进行Active Directory身份验证,这是以下代码。

public UserModel Get()
{
        UserModel currentUser = new UserModel();
        currentUser.name = User.Identity.Name;
      //  currentUser.auth = contactFromAD(User.Identity.Name);
        currentUser.auth = true;
        return currentUser;
}

因此,它所做的是检查你登录了哪个AD帐户,然后执行一些逻辑来检查你是否通过了访问该网站的身份验证。

然而,我如何才能在localhost之外使其工作呢。当代码运行在服务器上时,我如何让User.Identity.Name返回当前使用该应用程序的人的身份。

C#Active Directory身份验证

我不确定我是否理解AngularJS角度。如果我有一个常规的WCF服务,我会使用ServiceSecurityContext.Current中的WindowsIdentity。
http://msdn.microsoft.com/en-us/library/system.servicemodel.servicesecuritycontext.aspx

ServiceSecurityContext securityContext = ServiceSecurityContext.Current;
if (securityContext == null)
     throw new Exception("Failed to retrieve Service Security Context");
WindowsIdentity identity = securityContext.WindowsIdentity;
currentUser.name = identity.Name