当前位置: 首页>>代码示例>>C#>>正文


C# WindowsImpersonationContext.Dispose方法代码示例

本文整理汇总了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;
        }
开发者ID:avs009,项目名称:gsf,代码行数:38,代码来源:UserInfo.cs

示例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();
 }
开发者ID:CocoaLab,项目名称:WestwindToolkit,代码行数:9,代码来源:SecurityUtils.cs


注:本文中的System.Security.Principal.WindowsImpersonationContext.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。