Hi,
I have a WPF app written in C# 3.5
I have created a custom principal and attach it to the thread in my main
window with the following code...
CustomPrincipal principal = new CustomPrincipal(new
CustomUser(), new string[0]);
Thread.CurrentPrincipal = principal;
Now, I have the following line in another WPF window to get the custom
principal from the thread to check the user, but I get an error saying I
cannot cast a generic principal to my custom principal (note, if I put this
line straight after the code to set the principal above then it casts the
principal without any problems)
CustomUser user =
(CustomUser)((CustomPrincipal)Thread.CurrentPrincipal).Identity;

Signature
Regards,
Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
Jacob - 09 Mar 2008 20:15 GMT
Try
CustomPrincipal cp = (Thread.CurrentPrincipal) As CustomPrincipal
Then you should be able to get access to the members through the cp.whatever
normal accessor. This worked for me in a webapp I have with a custom login
principal.
> Hi,
>
[quoted text clipped - 15 lines]
> CustomUser user =
> (CustomUser)((CustomPrincipal)Thread.CurrentPrincipal).Identity;
Phil Johnson - 09 Mar 2008 20:41 GMT
Hi Jacob,
Thanks for the response. I already managed to get this one working by
setting the principal on the application's current domain. Don't know if wpf
windows run on different threads or something but that seems to be working
for me.

Signature
Regards,
Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
> Try
>
[quoted text clipped - 23 lines]
> > CustomUser user =
> > (CustomUser)((CustomPrincipal)Thread.CurrentPrincipal).Identity;