Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phil Johnson - 09 Mar 2008 18:34 GMT
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;

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.