I am working on an ASP.NET MVC 4 web application. After creating the user and account (using WebSecurity.CreateUserAndAccount), I want to continue working with this user, for example. to use it as a foreign key in another model.
One approach is to provide the UserProfile to the user UserId and use this UserId to query the user. For instance:
... try { int CustomUserId = Rnd.Next(1000000, 9999999); WebSecurity.CreateUserAndAccount(RegisterModel.UserName, RegisterModel.Passwordword, propertyValues: new { UserId = CustomUserId }); WebSecurity.Login(UserName, Password); var UserProfile = (from UserProf in _db.UserProfiles where UserProf.UserId == CustomUserId select UserProf).FirstOrDefault(); CustomModel cm = new CustomModel(); cm.User = UserProfile;
It seems rather inelegant to me. Especially because of the support of UserId on its own. Is there a more elegant way to solve this problem?
source share