CSLA Custom Membership Question

CSLA Custom Membership Question

Old forum URL: forums.lhotka.net/forums/t/10359.aspx


cslasoup posted on Tuesday, May 10, 2011

Hi,

I'm just learning CSLA and have a decent grasp on how to use it but I am having an issue with the custom membership portion.  I am trying to implement a password recovery page and once the user inputs their user name, as per standard functionality, the PasswordRecovery control calls the GetUser(username, userIsOnline) overload in the custom membership provider.

Now, my understanding is that in this function, I am to implement whatever data access I have to retrieve the user's information, store it into a MembershipUser object, and return that so that it gets passed on to next part of the procedure.  My problem is that I can't cast the user info (stored in a custom identity object which, in turn, is stored into a custom principal object; this is done per the VB 2008 book) to a MembershipUser object.

I've looked far and wide for a solution to this and the closest thing I've found is to have the custom identity inherit from CslaIdentity BUT I cannot see it when I try to subclass it.  Also, per the book's example, the identity object is currently inheriting from ReadOnlyBase(Of CustomIdentity) Implements IIdentity

I do my best to find things out on my own but have hit a brick wall on this issue.  Any help will be greatly appreciated.

RockfordLhotka replied on Tuesday, May 10, 2011

In the Using CSLA 4: Data Portal Configuration ebook I recommend and show how to subclass CslaIdentityBase<T> to create a custom identity object. The CSLA 4 CslaIdentityBase<T> class is a subclass of ROB, implements IIdentity, and also ICheckRoles so it automatically integrates with a CslaPrincipal subclass.

If you have no custom state in your identity type, creating this subclass is pretty trivial, because you just implement factory methods and DataPortal_Fetch (or a factory class with a Fetch method).

The CustomPrincipal class is a subclass of CslaPrincipal, and implements static methods named Login and Load. The Load method loads the identity based on username alone, and exists to support the stateless web server model. The only code in this subclass are these methods (and a static Logout method, because I like the symmetry that provides).

RockfordLhotka replied on Tuesday, May 10, 2011

Also, the custom principal and identity in the upcoming refresh of ProjectTracker follows the model from the ebook. You can view the code here:

http://www.lhotka.net/cslacvs/viewvc.cgi/core/trunk/Samples/NET/cs/ProjectTracker/

cslasoup replied on Wednesday, May 11, 2011

[EDIT] Hi Rocky.  Thanks for the reply.  I should have mentioned that we are using the 3.5.3 version of the Csla.dll because a requirement by the customer is that we use VB.  Does that change anything you mentioned?

RockfordLhotka replied on Wednesday, May 11, 2011

Then you need to subclass ReadOnlyBase and implement IIdentity yourself. You also need to implement IsInRole in your principal, because the automatic hookup provided by ICheckRoles didn't exist at that time (I don't think anyway).

You might mention to your customer that they can continue to use VB against CSLA .NET with current versions. It is just that CSLA itself isn't in VB anymore, just like 99% of the .NET framework.

cslasoup replied on Wednesday, May 11, 2011

Thanks again for the reply Rocky.  Understood as far as using the current versions of CSLA.NET with VB.  The principal's explanation for using this version of CSLA.NET was due to an issue with the CodeSmith templates.  I'll have to follow up with him later today about this and make sure we absolutely can't use the latest .NET 3.5 version.

I'll update the post when I have an answer/solution to my problem.

cslasoup replied on Friday, May 13, 2011

[UPDATE] I spoke with the principal and he informed me that 3.5.3 was only used because it had samples that could be used for training purposes to help ramp up other developers.  It had nothing to do with generating code with CodeSmith.

Regarding the question, I updated the .dll to 3.8.3 and subclassed the custom Identity class with CslaIdentity.  My problem still exists but it's not an issue with CSLA.  After researching more I found that we should also probably roll up another custom class that subclasses MembershipUser, retrieve the data from the database, and store those values into the custom MembershipUser properties.  I've never had to use the ASP.NET membership API so I'm still a little green with it.  

My initial problem was getting a MembershipUser object out of the API and I was hoping that I could somehow do that automatically from the custom Identity or Principal classes but it looks like it has to be wired up separately.

Thanks for all your hard work Rocky!

RockfordLhotka replied on Friday, May 13, 2011

If you are populating your custom identity from the Membership and Roles objects, you may consider buying Using CSLA 4: Data Portal Configuration, because I specifically walk through that entire scenario.

The ProjectTracker code in svn (in core/trunk) does this too.

Copyright (c) Marimer LLC