Click or drag to resize

UserInfoEndImpersonation Method

Ends the impersonation of the specified user.

Namespace: GSF.Identity
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.218-beta+101eee949414e414795e55a6e73d88938f0177b8
Syntax
public static void EndImpersonation(
	WindowsImpersonationContext impersonatedUser
)
View Source

Parameters

impersonatedUser  WindowsImpersonationContext
WindowsImpersonationContext of the impersonated user.
Example
This example shows how to terminate an active user impersonation:
C#
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