简体   繁体   中英

C# Active Directory authentication

I have a heavy client side webapp in AngularJS. I'm using a C# controller to do Active Directory authentication, here is this code.

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

So what its doing is checking what AD account you are logged into, then performing some logic to check if you are authenticated to access the site.

However how can I get this to work outside of localhost. When the code is running server, how can I get User.Identity.Name to return the identity of the person currently using the app.

I am not sure I understand AngularJS angle. If I had a regular WCF service I would use WindowsIdentity from ServiceSecurityContext.Current.
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM