本文整理汇总了C#中System.Security.Principal.WindowsImpersonationContext.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# WindowsImpersonationContext.Dispose方法的具体用法?C# WindowsImpersonationContext.Dispose怎么用?C# WindowsImpersonationContext.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Principal.WindowsImpersonationContext
的用法示例。
在下文中一共展示了WindowsImpersonationContext.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EndImpersonation
/// <summary>
/// Ends the impersonation of the specified user.
/// </summary>
/// <param name="impersonatedUser"><see cref="WindowsImpersonationContext"/> of the impersonated user.</param>
/// <example>
/// This example shows how to terminate an active user impersonation:
/// <code>
/// using System;
/// using System.IO;
/// using System.Security.Principal;
/// using PCS.Identity;
///
/// class Program
/// {
/// static void Main(string[] args)
/// {
/// // Impersonate user.
/// WindowsImpersonationContext context = UserInfo.ImpersonateUser("XYZCorp", "johndoe", "password");
/// // Perform operation requiring elevated previleges.
/// Console.WriteLine(File.ReadAllText(@"\\server\share\file.xml"));
/// // End the impersonation.
/// UserInfo.EndImpersonation(context);
///
/// Console.ReadLine();
/// }
/// }
/// </code>
/// </example>
public static void EndImpersonation(WindowsImpersonationContext impersonatedUser)
{
if (impersonatedUser != null)
{
impersonatedUser.Undo();
impersonatedUser.Dispose();
}
impersonatedUser = null;
}
示例2: RevertImpersonation
/// <summary>
/// Releases an impersonation context and releases associated resources
/// </summary>
/// <param name="context">WindowsImpersonation context created with ImpersonateUser</param>
public static void RevertImpersonation(WindowsImpersonationContext context)
{
context.Undo();
context.Dispose();
}