473,385 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Running spawned worker thread as impersonated user

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()
Feb 16 '06 #1
2 5212
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
}
}
"Patrick" <pa**@reply.newsgroup.msn.com> wrote in message
news:B3**********************************@microsof t.com...
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()

Feb 16 '06 #2
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?


"Bruce Barker" wrote:
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
}
}
"Patrick" <pa**@reply.newsgroup.msn.com> wrote in message
news:B3**********************************@microsof t.com...
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()


Feb 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John | last post by:
If my main UI thread starts a worker thread, who starts its own worker thread. So if i just close my app, in the closing event i can kill the thread the UI thread starts. but how can i kill the...
3
by: zhaoyandong | last post by:
I have two threads, one UI thread, the other, the worker thread, which is responsible for keeping on search things and post the found results to a list control on the UI. My leader doesn't allow...
7
by: Oenone | last post by:
Sorry for the cross-post but I've really no idea where this is best suited. I've an ADO.NET application which connects to a SQL Server database. I have spent the entire morning trying to get it...
6
by: Joe Jax | last post by:
I have an object that spawns a worker thread to process one of its methods. That method processes methods on a collection of other objects. During this processing, a user may request to cancel the...
4
by: Eric | last post by:
Hi, When I create a program with a form, the form doesn't go away until I close it somehow. How is this done, can it also be done with a module or a class? What I seek is this: I wrote a...
1
by: Dean Hinson | last post by:
Hello, I am trying to spawn a sunroutine in a worker thread for populating a trreeview. I set the selectednode and then start the thread. However, the thread errors because the selectednode was...
14
by: joey.powell | last post by:
I am using VS2005 for a windows forms application. I need to be able to use a worker thread function to offload some processing from the UI thread. The worker thread will need access to a...
6
by: seb | last post by:
Hi, I am using pygtk for the first times. I am wondering what would be the best "pattern" to interface pygtk with a thread. The thread is collecting informations (over the network for...
4
by: =?Utf-8?B?QW1yaXQgS29obGk=?= | last post by:
Hello, I have a button that starts up a Thread and runs it in the background. While the Thread is running, all the Ajax controls, including the events fired by the PageRequestManager, stop...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.