|
UserInfoEndImpersonation Method
|
Ends the impersonation of the specified user.
Namespace: GSF.IdentityAssembly: GSF.Core (in GSF.Core.dll) Version: 2.4.284-beta+805ed69bbaa748bda5f49830845a2ffff2791ae0
Syntax
Example
This example shows how to terminate an active user impersonation:
using System;
using System.IO;
using System.Security.Principal;
using GSF.Identity;
class Program
{
static void Main(string[] args)
{
// Impersonate user.
WindowsImpersonationContext context = UserInfo.ImpersonateUser("XYZCorp", "johndoe", "password");
// Perform operation requiring elevated privileges.
Console.WriteLine(File.ReadAllText(@"\\server\share\file.xml"));
// End the impersonation.
UserInfo.EndImpersonation(context);
Console.ReadLine();
}
}
See Also