473,564 Members | 2,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running spawned worker thread as impersonated user

I have an ASP.NET web service whose Web.Config is set to use impersonation

<authenticati on mode="Windows" />
<identity impersonate="tr ue" />
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.Threadin g.Thread = New
System.Threadin g.Thread(Addres sOf reportManager.R unReport)
worker.Start()
Feb 16 '06 #1
2 5228
you need to pass the creditials of the current thread to the new created
thread.
class foo()
{
private WindowsIdentity mThreadIdentity = null;
[DllImport("adva pi32")] static extern bool RevertToSelf();

public void StartThread()
{
// setup thread

ThreadStart ts = new ThreadStart(Run Report);
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.new sgroup.msn.com> wrote in message
news:B3******** *************** ***********@mic rosoft.com...
I have an ASP.NET web service whose Web.Config is set to use impersonation

<authenticati on mode="Windows" />
<identity impersonate="tr ue" />
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.Threadin g.Thread = New
System.Threadin g.Thread(Addres sOf reportManager.R unReport)
worker.Start()

Feb 16 '06 #2
my reportManager.R unReport 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("adva pi32")]
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("adva pi32")] static extern bool RevertToSelf();

public void StartThread()
{
// setup thread

ThreadStart ts = new ThreadStart(Run Report);
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.new sgroup.msn.com> wrote in message
news:B3******** *************** ***********@mic rosoft.com...
I have an ASP.NET web service whose Web.Config is set to use impersonation

<authenticati on mode="Windows" />
<identity impersonate="tr ue" />
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.Threadin g.Thread = New
System.Threadin g.Thread(Addres sOf reportManager.R unReport)
worker.Start()


Feb 17 '06 #3

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

Similar topics

1
8971
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 worker thread that the UI thread's worker thread started?
3
1374
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 me to use MFC. So I have to use SendMessage(LVM_XXX, hListCtrl) in the worker thread, I guess. But I failed, there is nothing displaying in...
7
1498
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 to connect, but eventually got it working by setting (in the web.config file) the authentication mode to "Windows" and the identity impersonate flag...
6
5980
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 entire operation. I could request abort on the worker thread, but that is a) potentially messy, and b) not guaranteed to take immediate effect...
4
1189
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 program that runs in a sub Main(). At this moment I use a DO WHILE LOOP to have the program do something every
1
1295
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 found to equal "Nothing". Is there some kind of trick to get the threaded subroutine to see the selectednode to process? Thank you inadvance...
14
6858
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 datagridview on the form. I am using the following code to spawn the worker thread... Thread WorkerThread = new Thread(new ThreadStart(WT_MyFunction));...
6
2853
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 example) or is doing some long calculations.
4
1656
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 firing until the Thread exits. So, I have no way of updating the page while this Thread is running, which was the point of putting it on the Thread. ...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.