Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > need clear example of threading + impersonation

Reply
Thread Tools

need clear example of threading + impersonation

 
 
jyjohnson
Guest
Posts: n/a
 
      03-03-2005
My asp.net application needs to allow the user (via basic authentication) to
execute a long running process (new thread) that writes files out to a share
on another server.

This works if I just use impersonation without creating a new thread. I'm
using XP Pro + IIS 5. I think I have access to a Win 2003 server if that
makes things easier.

Thanks....


 
Reply With Quote
 
 
 
 
Dominick Baier [DevelopMentor]
Guest
Posts: n/a
 
      03-03-2005
Hello jyjohnson,

i assume that you first impersonate and start the thread afterwards....

impersonation tokens are not copied to new threads in .net 1.1 (they will
in 2.0)

do it like this

start the thread
impersonate the user on the new thread

something like (only compiled in the newsreader


Worker worker = new Worker();
worker.user = Page.User;

Thread t = new Thread(new ThreadStart(worker.DoWork);

class Worker
{
public WindowsPrincipal user;

public void DoWork()
{
WindowsImpersonationContext ctx;
try
{
user.Impersonate();
}
finally
{
ctx.Undo();
}
}
}


---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

> My asp.net application needs to allow the user (via basic
> authentication) to execute a long running process (new thread) that
> writes files out to a share on another server.
>
> This works if I just use impersonation without creating a new thread.
> I'm using XP Pro + IIS 5. I think I have access to a Win 2003 server
> if that makes things easier.
>
> Thanks....
>




 
Reply With Quote
 
 
 
 
jyjohnson
Guest
Posts: n/a
 
      03-03-2005
I think I've tried that.... I've tried many code snips, etc, ! I understand
the problem (i.e., new threads use the aspnet account identity, not the
impersonated identity)...

I get an error on this line ---> user.Impersonate 'not a member of
WindowsPrinciple

Thanks!


"Dominick Baier [DevelopMentor]" wrote:

> Hello jyjohnson,
>
> i assume that you first impersonate and start the thread afterwards....
>
> impersonation tokens are not copied to new threads in .net 1.1 (they will
> in 2.0)
>
> do it like this
>
> start the thread
> impersonate the user on the new thread
>
> something like (only compiled in the newsreader
>
>
> Worker worker = new Worker();
> worker.user = Page.User;
>
> Thread t = new Thread(new ThreadStart(worker.DoWork);
>
> class Worker
> {
> public WindowsPrincipal user;
>
> public void DoWork()
> {
> WindowsImpersonationContext ctx;
> try
> {
> user.Impersonate();
> }
> finally
> {
> ctx.Undo();
> }
> }
> }
>
>
> ---------------------------------------
> Dominick Baier - DevelopMentor
> http://www.leastprivilege.com
>
> > My asp.net application needs to allow the user (via basic
> > authentication) to execute a long running process (new thread) that
> > writes files out to a share on another server.
> >
> > This works if I just use impersonation without creating a new thread.
> > I'm using XP Pro + IIS 5. I think I have access to a Win 2003 server
> > if that makes things easier.
> >
> > Thanks....
> >

>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: threading in PyQt vs threading in standard library Steven Woody Python 0 01-09-2009 07:48 AM
threading in PyQt vs threading in standard library Steven Woody Python 0 01-09-2009 07:15 AM
Cooperative threading preemptive threading - a bit confused failure_to@yahoo.co.uk Java 9 12-29-2007 01:10 AM
Threading & Impersonation =?Utf-8?B?UGF0cmljaw==?= ASP .Net 1 02-17-2006 02:53 AM
Need an example about threading in ASP.Net Lea Heart ASP .Net 1 08-28-2003 04:42 PM



Advertisments