Example #1
0
 public void Release()
 {
     if (this.IsImpersonated && (Interlocked.Decrement(ref this.refCount) == 0))
     {
         lock (this.tokenHandle)
         {
             this.tokenHandle.Close();
             this.tokenHandle = null;
         }
     }
 }
Example #2
0
 public void Release()
 {
     if (IsImpersonated)
     {
         Fx.Assert(tokenHandle != null, "The token handle is incorrectly released earlier.");
         int currentCount = Interlocked.Decrement(ref refCount);
         if (currentCount == 0)
         {
             lock (tokenHandle)
             {
                 tokenHandle.Close();
                 tokenHandle = null;
             }
         }
     }
 }
Example #3
0
 public HostedImpersonationContext()
 {
     if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
     {
         int num;
         if (SafeNativeMethods.OpenCurrentThreadTokenCritical(TokenAccessLevels.Query | TokenAccessLevels.Impersonate, true, out this.tokenHandle, out num))
         {
             this.isImpersonated = true;
             Interlocked.Increment(ref this.refCount);
         }
         else
         {
             CloseInvalidOutSafeHandleCritical(this.tokenHandle);
             this.tokenHandle = null;
             if (num != 0x3f0)
             {
                 throw FxTrace.Exception.AsError(new Win32Exception(num, System.ServiceModel.Activation.SR.Hosting_ImpersonationFailed));
             }
         }
     }
 }
Example #4
0
        public HostedImpersonationContext()
        {
            if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
            {
                int  error;
                bool isSuccess = SafeNativeMethods.OpenCurrentThreadTokenCritical(TokenAccessLevels.Query | TokenAccessLevels.Impersonate,
                                                                                  true, out tokenHandle, out error);

                if (isSuccess)
                {
                    isImpersonated = true;
                    Interlocked.Increment(ref refCount);
                }
                else
                {
                    CloseInvalidOutSafeHandleCritical(tokenHandle);
                    tokenHandle = null;
                    if (error != SafeNativeMethods.ERROR_NO_TOKEN)
                    {
                        throw FxTrace.Exception.AsError(new Win32Exception(error, SR.Hosting_ImpersonationFailed));
                    }
                }
            }
        }