private static IntPtr GetCurrentToken()
        {
            IntPtr zero = IntPtr.Zero;

            if ((UnsafeNativeMethods.OpenThreadToken(UnsafeNativeMethods.GetCurrentThread(), 0x2000c, true, ref zero) == 0) && (Marshal.GetLastWin32Error() != 0x3f0))
            {
                throw new HttpException(System.Web.SR.GetString("Cannot_impersonate"));
            }
            return(zero);
        }
Пример #2
0
            private static IntPtr GetCurrentToken()
            {
                IntPtr token = IntPtr.Zero;

                if (UnsafeNativeMethods.OpenThreadToken(
                        UnsafeNativeMethods.GetCurrentThread(),
                        UnsafeNativeMethods.TOKEN_READ | UnsafeNativeMethods.TOKEN_IMPERSONATE,
                        true,
                        ref token) == 0)
                {
                    // if the last error is ERROR_NO_TOKEN it is ok, otherwise throw
                    if (Marshal.GetLastWin32Error() != UnsafeNativeMethods.ERROR_NO_TOKEN)
                    {
                        throw new HttpException(HttpRuntime.FormatResourceString(SR.Cannot_impersonate));
                    }
                }

                return(token);
            }