Implementing Profile Provider in ASP.NET MVC

Here's what you need to do:

1) In Web.config's section, add "inherits" attribute in addition to your other attribute settings:

<profile inherits="MySite.Models.ProfileCommon" defaultProvider="....

2) Remove entire <properties> section from Web.config, since you have already defined them in your custom ProfileCommon class and also instructed to inherit from your custom class in previous step

3) Change the code of your ProfileCommon.GetProfile() method to

public virtual ProfileCommon GetProfile(string username)        
{            
     return Create(username) as ProfileCommon;      
}

Hope this helps.


Not sure about the whole question, but one thing I noticed in your code:

ProfileCommon profile = (ProfileCommon)ProfileCommon.Create(user.UserName, user.IsApproved) as ProfileCommon;

You do not need both the (ProfileCommon) and the as ProfileCommon. They both do casts, but the () throws and exception while the as returns a null if the cast can't be made.


Try Web Profile Builder. It's a build script that automagically generates a WebProfile class (equivalent to ProfileCommon) from web.config.


The web.config file in the MVC Beta is wrong. The SqlProfileProvider is in System.Web.Profile, not System.Web.Security. Change this, and it should start working for you.