1

Is it possible to add fields/columns to webpages_Membership?

[Table("webpages_Membership")]
public class Membership
{
public Membership()
{
    Roles = new List<Role>();
    OAuthMemberships = new List<OAuthMembership>();
}

[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public int UserId { get; set; }
public DateTime? CreateDate { get; set; }
[StringLength(128)]
public string ConfirmationToken { get; set; }
public bool? IsConfirmed { get; set; }
public DateTime? LastPasswordFailureDate { get; set; }
public int PasswordFailuresSinceLastSuccess { get; set; }
[Required, StringLength(128)]
public string Password { get; set; }
public DateTime? PasswordChangedDate { get; set; }
[Required, StringLength(128)]
public string PasswordSalt { get; set; }
[StringLength(128)]
public string PasswordVerificationToken { get; set; }
public DateTime? PasswordVerificationTokenExpirationDate { get; set; }

public ICollection<Role> Roles { get; set; }

[ForeignKey("UserId")]
public ICollection<OAuthMembership> OAuthMemberships { get; set; }
}

I want to add LogonCount as a field/column, but this table gets filled automatically by the membership provider upon creating a CreateUserAndAccount().

I don't seem to have any influence on giving the LogonCount a value at CreateUserAndAccount().

Yustme
  • 6,125
  • 22
  • 75
  • 104

1 Answers1

1

The standard way to add information relevant to a given userId is in the UserProfile table, not the webpages_Membership table. See my answer here and Jon Galloway's post on "SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates" for more info about how SimpleMembership ties together with UserProfile.

I don't seem to have any influence on giving the LogonCount a value ...

You then access the UserProfile table and information through your database context, not through the membership provider, which is really there to give you access to a core set of features only.

using (MyDbContext db = new MyDbContext())
{
  UserProfile user = db.UserProfiles
    .First(u => u.UserName.ToLower() == model.UserName.ToLower());
  user.LogonCount = 1;
  db.SaveChanges();
}
Community
  • 1
  • 1
Andy Brown
  • 18,961
  • 3
  • 52
  • 62
  • Hi, ok, so webpages_Membership is off limits. got it. – Yustme May 18 '13 at 19:29
  • You probably could use it, but you don't want to as the membership provider cares about it's schema just as much as you do – Andy Brown May 18 '13 at 19:47
  • @Yustme. Added a ref in the answer to [my SO answer here](http://stackoverflow.com/a/16734651/1945631) for more info about how SimpleMembership ties together with `UserProfile`, which might help as well. – Andy Brown May 24 '13 at 12:36
  • Andy, I'm very jealous about the answer he got from you! :o But thanks! – Yustme May 25 '13 at 10:04