need clear example of threading + impersonation

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default need clear example of threading + impersonation

    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....


    jyjohnson Guest

  2. Similar Questions and Discussions

    1. Threading within a service
      Hi there, I hope someone can help me. I have a client app. being used by about 50 users. When thy open the app, it calls a webservice on a...
    2. no neutral threading in win 2003?
      Hi All, I have a COM component written in C++ which is inteneded to be stored in the Application object. This means of course that I had to write...
    3. Threading model to 'Any Apartment'
      Hey guys, i am relatively new to this COM+ thing, i am trying to figure out where do i set the threading model for my application as 'any...
    4. Threading and Session Objects
      Hi, I´m doing an asp.net application that uploads and downloads files and folders between the client and the server on my intranet. To do this I...
    5. Threading / sockets bug
      Where do I report this bug? Only happens on windows platform: causes some error ot lock that doesnt occur on Unices require \'socket\'...
  3. #2

    Default Re: need clear example of threading + impersonation

    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
    [url]http://www.leastprivilege.com[/url]
    > 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....
    >


    Dominick Baier [DevelopMentor] Guest

  4. #3

    Default Re: need clear example of threading + impersonation

    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
    > [url]http://www.leastprivilege.com[/url]
    >
    > > 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....
    > >
    >
    >
    >
    >
    jyjohnson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139