| 
            
              UserInfoImpersonateUser Method
             | 
          
        
        
             Impersonates the specified user.
             
        
        Namespace: GSF.IdentityAssembly: GSF.Core (in GSF.Core.dll) Version: 2.4.257-beta+00aa2366fbb9ec75f636ebc7cfa610e3826a727c
Syntaxpublic static WindowsImpersonationContext ImpersonateUser(
	string domain,
	string userName,
	string password
)
Public Shared Function ImpersonateUser ( 
	domain As String,
	userName As String,
	password As String
) As WindowsImpersonationContext
public:
static WindowsImpersonationContext^ ImpersonateUser(
	String^ domain, 
	String^ userName, 
	String^ password
)
static member ImpersonateUser : 
        domain : string * 
        userName : string * 
        password : string -> WindowsImpersonationContext GSF.Identity.UserInfo.ImpersonateUser = function(domain, userName, password);
 View SourceParameters
- domain  String
 - Domain of user to impersonate.
 - userName  String
 - Username of user to impersonate.
 - password  String
 - Password of user to impersonate.
 
Return Value
WindowsImpersonationContextA 
WindowsImpersonationContext object of the impersonated user.
Remarks
             After impersonating a user the code executes under the impersonated user's identity.
             
Example
             This example shows how to impersonate a user:
             
using System;
using GSF.Identity;
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(string.Format("User before impersonation: {0}", UserInfo.CurrentUserID));
        UserInfo.ImpersonateUser("XYZCorp", "johndoe", "password"); 
        Console.WriteLine(string.Format("User after impersonation: {0}", UserInfo.CurrentUserID));
        Console.ReadLine();
    }
}
See Also