2

After lot of research and attempts I failed, here is the situation :

Technologies

  • Asp.Net MVC4
  • Entity Framework Code First
  • SQL Server 2008

I used Code First to create my domain classes, example :

public class Country{
   public int IdCountry {get;set;}
   public int NameCountry {get;set;}
}
public class Sex{
   public int IdSex {get;set;}
   public int NameSex{get;set;}
}

etc... I have like 20 classes

All I want is :

Use the Asp.Net Membership system, and plug it to my classes. I have a domain class called UserProfile

public class UserProfile{
   public int IdUserProfile {get;set;}
   public virtual Sex sex {get;set;}
   public virtual Country country {get;set;}
   public virtual ICollection<Photos> photos {get;set;}
   etc...
}

I want to be able to connect all this with the Asp.Net User registered via Asp.Net Membership and the AccountController

I search in stackoverflow, codeplex etc.. and I dont find a solution for that or perhaps I did not understand.

I hope someone have achieved this in real world application :)

ps : I am working on a "dating" Website

tereško
  • 58,060
  • 25
  • 98
  • 150
Hassan
  • 1,413
  • 1
  • 10
  • 12
  • Have a look at the [SimpleMembership](http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx) provider which comes with web matrix. – StuartLC Sep 16 '12 at 18:04
  • I have tested the SimpleMemebership but I my attemps to make a relationship between my domain class and the UserProfile were unsuccessful. There is not much documentation about how to integrate the simplemembership with the other domain classes – Hassan Sep 16 '12 at 19:59

1 Answers1

3

The AccountController in MVC 4 already relies on SimepleMembership and other WebMatrix bits to support membership with both OAuth and local accounts.

My suggestion would be to start by removing the DbContext derived class defined in the AccountModel.cs for your MVC 4 project and replacing it with your own (the compiler errors will tell you what you have to change once you remove the class).

I'd also remove the SimpleMembershipInitializerAttribute from the project and make sure to perform the initialization tasks during Application_Start instead. The filter has a few subtle flaws. When I get a chance to post about this, I'll update this with a URL.

OdeToCode
  • 4,906
  • 23
  • 18
  • It's exactly the way I used before I read your answer :) Perfect ! – Hassan Sep 19 '12 at 17:12
  • Yeah, SimpleMembership just doesn't work the way you would expect a membership provider to work and one of the places it falls down is with configuration. You do have to manually load that one, I believe :( – OdeToCode Oct 04 '12 at 17:48