views:

33

answers:

1

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

A: 

FormsAuthentication.SetAuthCookie(userName, saveLogin);

Hope this helps. MSDN Documentation for SetAuthCookie Method

pjb
thanks, Maybe i could not explain myself, FormsAuthentication.SetAuthCookie(userNmae,SaveLogin) is automatically called when we call signIn(userName, SaveLogin) function. this will store userName info in the cookie that is available through httpContext.Current.User.__. what i want is to store custom information i.e company number and employee id in the cookie so that i could access that using httpContext.Current.User.EmployeeID and so on. is it possible and what classes i have to implement for thisRegardsAdeel
Muhammad Adeel Zahid