Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

Running spawned worker thread as impersonated user

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick - 16 Feb 2006 14:13 GMT
I have an ASP.NET web service whose Web.Config is set to use impersonation

   <authentication mode="Windows" />  
   <identity impersonate="true" />

Within a Web Method, I want to use Multi-threading to spawn off an
asynchronous process, as it takes quite long to return. How could I get the
worker thread to runas the same impersonated user on ASP.NET?

       Dim worker As System.Threading.Thread = New
System.Threading.Thread(AddressOf reportManager.RunReport)
       worker.Start()
Bruce Barker - 16 Feb 2006 19:02 GMT
you need to pass the creditials of the current thread to the new created
thread.

class foo()
{
     private WindowsIdentity mThreadIdentity = null;
     [DllImport("advapi32")] static extern bool RevertToSelf();

     public void StartThread()
     {
           // setup thread

            ThreadStart ts = new ThreadStart(RunReport);
            Thread t  = new Thread(ts);
            mThreadIdentity  = WindowsIdentity.GetCurrent();

            // drop any impersonation

            RevertToSelf();

            // start thread

             t.Start();

           // restore thread identity

           mThreadIdentity.Impersonate();

      }

       private void RunReport()
       {
           mThreadIdentity.Impersonate();
           // do whatever
       }
}

>I have an ASP.NET web service whose Web.Config is set to use impersonation
>
[quoted text clipped - 9 lines]
> System.Threading.Thread(AddressOf reportManager.RunReport)
>        worker.Start()
Patrick - 17 Feb 2006 10:24 GMT
my reportManager.RunReport is in a *different* class from the web method that
spawn it off.  Hence, it won't be able to reference mThreadIdentity.

In addition, could you clarify the definition of [DllImport("advapi32")]
static extern bool RevertToSelf();  .e.g. what is the EntryPoint?

> you need to pass the creditials of the current thread to the new created
> thread.
[quoted text clipped - 46 lines]
> > System.Threading.Thread(AddressOf reportManager.RunReport)
> >        worker.Start()

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.