That's going to depend entirely on WHEN and WHERE you assign your custom object to the Context.CurrentUser.
 
If you've assigned it at every request, then the cast should work. If you're just assigning your custom object at the initial login, and you're relying on the ASP.NET forms-based authentication to determine if the user is authenticated, then you're going to get a GenericPrincipal which will never cast to your custom object.
 
The ASP.NET samples don't really speak very clearly about this, so it's a common mistake. So, to speak declaratively: if you want access to your custom IPrincipal, you MUST assign it to the Context.CurrentUser at each request.
 
This can lead to many hits on the database, unless you've got the second-level cache enabled. One of the things I'll do is allow the GenericPrincipal to be assigned for resources that will not processed in the ASP.NET pipeline, and therefore a GenericPrincipal is acceptable (like images).
 
- Richard


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Berkenbosch
Sent: Friday, August 04, 2006 12:53 PM
To: castleproject-users@lists.sourceforge.net
Subject: [Castle-users] Getting IPrinciple as Model Object

Hi List,

I suppose this is something rather trivial but I can;t seem te find it. I would like to display the properties of the current logged in user. This is ofcourse an IPrinciple.

Suppose I have an User model that simply implements the IPrinciple interface. I then should be able to do something like :

MyModel.User  user = Context.CurrentUser as MyModel.User

Or is the wine that I've been drinking the issue ? :)

Thanks
Peter

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
CastleProject-users mailing list
CastleProject-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/castleproject-users

Reply via email to