>>private void TestSecurityPrincipal() >>{ >> System.Security.Principal.GenericIdentity gi = new System.Security.Principal.GenericIdentity("BB"); >> System.Security.Principal.GenericPrincipal gp = new System.Security.Principal.GenericPrincipal(gi, new string[] { "Admin", "Backup" }); >> >> // Test the value of >> // Thread.CurrentPrincipal.Identity >> // before and after this breakpoint >> Thread.CurrentPrincipal = gp; >> >> // And again after this next statement executes >> System.AppDomain.CurrentDomain.SetThreadPrincipal(gp); >> >> // Next, we're going to open another Form, and try some stuff from that Form. >> //System.Security.Principal.IPrincipal g = System.Threading.Thread.CurrentPrincipal; >> //g.Identity >> >> Form4 oForm = new Form4(); >> oForm.Show(); >>} >>>>
>>System.Security.Principal.IPrincipal g = System.Threading.Thread.CurrentPrincipal;
>>// Test the value:
>>//g.Identity
>>
>>GenericIdentity g = new GenericIdentity("Viv"); >>>GenericPrincipal p = new GenericPrincipal(g,new string[]{"Admin","Backup"}); >>>Thread.CurrentPrincipal = p; >>>// System.AppDomain.CurrentDomain.SetThreadPrincipal(p); //Worksthen later (in a different form)
System.Security.Principal.IPrincipal g = System.Threading.Thread.CurrentPrincipal;
>>>but g.Identity at this point is an empty,unauthenticated instance (as it is before setting the Thread.CurrentPrincipal). If I use the CurrentDomain.SetThreadPrincipal version above instead then g.Identity is as expected. AFAICS this is still the same thread so why the difference?