Attach Custom Principal to Thead on one form, not there on other f

P

Phil Johnson

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;

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
 
J

Jacob

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

Phil Johnson

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.

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com


Jacob said:
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.

Phil Johnson said:
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;

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top