+2  A: 

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.

Mladen Mihajlovic
Oops! That's what I get for modifying the pasted code in my browser.Good catch.
senfo
+6  A: 

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

Dave Dunkin
Have you been able to verify that this works? I gave it a try and I'm still having the same issue.
senfo
I've used this to great success. Worked just fine. Just make sure you add the WebProfile.CS file to the project. I overlooked that and was frustrated for about an hour.
Ryan Skarin
This works fine, and is very much like working with the Web Forms Profile Provider.
bzlm
+1  A: 

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.

+11  A: 

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.

Worked like a charm. The only change I made was: public static new ProfileCommon Create( string username ) { return ProfileBase.Create( username ) as ProfileCommon; }
tvanfosson
I couldn't get this to work when creating a new user, so I asked a separate question, which led to a solution. If you find yourself in that situation, this might help:http://stackoverflow.com/questions/2547290/using-asp-net-membership-and-profile-with-mvc-how-can-i-create-a-user-and-set-i
Jeremy Gruenwald