Quantcast
Viewing all articles
Browse latest Browse all 764

Creating a Custom Membership Provider with MVC 4

I am creating a web site in VS2012 using ASP.NET MVC 4.  I am trying to implement the CustomMembershipProvider as Rocky describes on page 74 of the "UsingCSLA4-06-AspMvc" chapter Using CSLA 4 book series.

What I did:

1.  Created the CustomMembershipProvider class .  This implements the 'MembershipProvider' interface.

2.  Added the following to the system.web element of the web.config file to change the default provider for membership services to my CustomMembershipProvider.

<membership defaultProvider="CustomMembershipProvider">

<providers>

<add name="CustomMembershipProvider" type="webPACE.CustomMembershipProvider, webPACE" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" description="Retrieves membership data using CSLA .NET business objects."/>

</providers> 

 

3.  Added the following code the Application_AuthenticateRequest method in Global.asax.cs to set the principal on each request to the server.

protected void Application_AuthenticateRequest(Object sender, EventArgs e)

{

if (Csla.ApplicationContext.User != null && Csla.ApplicationContext.User.Identity.IsAuthenticated && Csla.ApplicationContext.User.Identity is FormsIdentity)

{ PACE.Library.Security.PacePrincipal.Load(Csla.ApplicationContext.User.Identity.Name);

}

}

I believe I followed the guidance in the book exactly; however, I get the following error when the Login method is called.

"To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".

I have a feeling this is somehow related to a change made in MVC 4 (as the book was written with MVC 3 in mind); however, my internet searches on the subject are just leaving me more confused. 

Has anyone else run into this when trying to create custom provider that uses CSLA business objects and what was the resolution?

Thanks for any assistance.

David.

 


Viewing all articles
Browse latest Browse all 764

Trending Articles