Storing User Information in Session with aspNetMembershipProvider

Posted by Muhammad Adeel Zahid on Stack Overflow See other posts from Stack Overflow or by Muhammad Adeel Zahid
Published on 2010-06-03T11:54:33Z Indexed on 2010/06/04 6:09 UTC
Read the original article Hit count: 345

Filed under:
|

Hi Everyone,

i m developing an application in .NET mvc2. i m using aspnetMembershipProvider for User registration and related activities. i need some custom information about user that i stored in a separate table (sysUser for example) and linked it to aspnetUser table through foreign key. after Login i need to fetch user's credentials from sysUser table and push it to the session. For this Account controller's Logon method seemed best to me and i pasted following code in my Logon ActionResult

 if (!ValidateLogOn(userName, password))
        {
            return View();
        }

        FormsAuth.SignIn(userName, rememberMe);
        ApplicationRepository _ApplicationRepository = new ApplicationRepository();
        MembershipUser aspUser = Membership.GetUser(userName);
        SessionUser CurrentUser = _ApplicationRepository.GetUserCredentials(aspUser.ProviderUserKey.ToString());

        //Session["CurrentUser"] = CurrentUser;

        if (!String.IsNullOrEmpty(returnUrl))
        {
            return Redirect(returnUrl);
        }
        else
        {
            return RedirectToAction("Index", "Home");
        }

The code is working perfectly for me and put my desired information in the session but the thing is that if a user selects Remember me and on his next visit he won't have to Log in and i would not find my desired information in the Session. Can anyone guide me where should i put my code that stores the user information in the session.
any Help is Highly appreciated
Regards
Adeel

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about membershipprovider