Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8747471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:21:42+00:00 2026-06-13T12:21:42+00:00

While studying SQL CLR stored procedure I came across following link Link for SQL

  • 0

While studying SQL CLR stored procedure I came across following link Link for SQL Bulk Copy in CLR .
In this link user has used
WindowsIdentity currentIdentity = SqlContext.WindowsIdentity;
WindowsImpersonationContext impersonatedIdentity = currentIdentity.Impersonate();

I am not able to understand what is the use of WindowsImpersonationContext .Without it’s use I am able to run my code.Can anybody tell me what is exact use of this Identity Impersonation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:21:43+00:00Added an answer on June 13, 2026 at 12:21 pm

    E.g. if you want to run a thread in the same context as the process, you could do something similar to this:

        private void ImpersonateThread()
        {
            new Thread(() =>
            {
                Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
                //Do the work...
            }).Start();
        }
    

    This is very useful if running a website (on MS-IIS) where the application-pool is running as one user and the authentication mode is set to windows authentication. Then you probably would like the threads to run as the user accessing the website.

    UPDATE:

    I just want to clarify this. The line:

      Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
    

    just transfer the user (the user is still not impersonated to the thread yet) to the thread so other components may see who the user are and use the information if necessary, e.g. like this:

            System.Security.Principal.WindowsImpersonationContext impersonationContext;
            impersonationContext =
                ((System.Security.Principal.WindowsIdentity)System.Threading.Thread.CurrentPrincipal.Identity).Impersonate();
                //Do the work that you want within the impersonated users context.
            impersonationContext.Undo();
    

    Between the impersonation and the Undo, the user is impersonated and all code is running as this user. I know the user is the same in this sample, but imagine that the thread holds a user entirely different from the user running the process (something a user has entered or similar). Hope this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While studying for a Functional Programming exam, I came across the following questions from
While studying for a Functional Programming exam, I came across the following question from
While studying for the Zend PHP Exam I came across the following contradicting information:
I came across this question while studying for the Microsoft Web-Application Developer exam, You
I came across these terms recently, while studying a program. I got an idea
i came upon this code while studying settimeout. the settimeout executes an alert 5
I've been studying jQuery for a while now, and just lately I came across
I came up with this example while studying mock exams for OCPJP certification, (from
While studying an implementation of Group signature I came across code where Group certificate
I just saw this code while studying the wordpress source code (PHP), You can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.