Home All Groups Group Topic Archive Search About

How to share a Principal within a ThreadPool ?

Author
26 Apr 2005 12:01 PM
Oriane
Hi,

when I set a Principal in the current thread, using :

Thread.CurentPrincipal =

the Principal object is not set in the other threads of the application
threadpool.

Is there a special way to do that ?

Oriane

Author
26 Apr 2005 5:52 PM
Dominick Baier [DevelopMentor]
Hello Oriane,

why would you like to do this??

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

Show quoteHide quote
> Hi,
>
> when I set a Principal in the current thread, using :
>
> Thread.CurentPrincipal =
>
> the Principal object is not set in the other threads of the
> application threadpool.
>
> Is there a special way to do that ?
>
> Oriane
>
Author
27 Apr 2005 8:41 AM
Oriane
"Dominick Baier [DevelopMentor]" <dbaier@pleasepleasenospamdevelop.com>
wrote in message news:304286632501419246158320@news.microsoft.com...
> Hello Oriane,
>
> why would you like to do this??
Good question ! I would like to do this because I want to handle the
authorization for "applicative users" in my app, which of course has many
threads. So if I set the principal in a thread (say the presentation one),
and then use declarative authorization with the PrincipalPermissionAttribute
in another thread, it won't work...
Author
27 Apr 2005 12:43 PM
Dominick Baier [DevelopMentor]
Hello Oriane,

set Context.User to the specific IPrincipal (e.g. in AuthenticateRequest)
- there is a "semi documented" event firing after AuthenticateRequest called
"DefaultAuthentication" which copies Context.User to Thread.CurrentPrincipal.
After that your PrincipalPermissions should work.

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

Show quoteHide quote
> "Dominick Baier [DevelopMentor]"
> <dbaier@pleasepleasenospamdevelop.com> wrote in message
> news:304286632501419246158320@news.microsoft.com...
>
>> Hello Oriane,
>>
>> why would you like to do this??
>>
> Good question ! I would like to do this because I want to handle the
> authorization for "applicative users" in my app, which of course has
> many threads. So if I set the principal in a thread (say the
> presentation one), and then use declarative authorization with the
> PrincipalPermissionAttribute in another thread, it won't work...
>
Author
27 Apr 2005 9:54 AM
Aleksandr Sliborsky
> Hi,
> when I set a Principal in the current thread, using :
> Thread.CurentPrincipal =
> the Principal object is not set in the other threads of the application
> threadpool.
> Is there a special way to do that ?
> Oriane
If You write an ASP.NET  application use Context.User instead of
Thread.CurrentPrincipal.
Contexct.User sets principal for all threads.
You can also use AppDomain.SetThreadPrincipal
But this method could be used only once.
Author
27 Apr 2005 10:10 AM
Oriane
"Aleksandr Sliborsky" <Aleksandr Slibor***@discussions.microsoft.com> wrote
in message news:6BB2A67C-C412-44D5-9B43-0050D8183166@microsoft.com...
[...]
> You can also use AppDomain.SetThreadPrincipal
> But this method could be used only once.
Fine.

Thanks
Author
27 Apr 2005 12:45 PM
Dominick Baier [DevelopMentor]
Hello Aleksandr,

That's not true. Context.User is for the current thread only. And you have
to do that for every request, e.g. in Application_AuthenticateRequest. This
is the recommended way of doing it.

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

Show quoteHide quote
>> Hi,
>> when I set a Principal in the current thread, using :
>> Thread.CurentPrincipal =
>> the Principal object is not set in the other threads of the
>> application
>> threadpool.
>> Is there a special way to do that ?
>> Oriane
> If You write an ASP.NET  application use Context.User instead of
> Thread.CurrentPrincipal.
> Contexct.User sets principal for all threads.
> You can also use AppDomain.SetThreadPrincipal
> But this method could be used only once.