Link to home
Start Free TrialLog in
Avatar of MickeC
MickeCFlag for Sweden

asked on

Asp.net mvc C# aspnet_Users add session for new field

Hallo,

I added a field in table 'aspnet_Users' in the default database cald 'fk_company_id', when the user login i want to grab the 'fk_company_id' and store it in a session to access it im my webb aplication. Im using microsoft default login. Im new att this any sugetions?

Controller:
public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Home", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

Moddel:
public bool ValidateUser(string userName, string password)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");

            return _provider.ValidateUser(userName, password);
        }

Avatar of Avodah
Avodah
Flag of United Kingdom of Great Britain and Northern Ireland image

I am not sure what your question since you seem to have it worked out. Are you asking how to do it, as in write the code to retrieve the data or you are asking where to put that code?

1. Check if user successfully logged on
http://msdn.microsoft.com/en-us/library/system.web.httprequest.isauthenticated.aspx
http://www.velocityreviews.com/forums/t371466-check-if-logged-in.html

2. Retrieve the data

3.  Store in session. Session["Something"] = 1;

DaTribe
ASKER CERTIFIED SOLUTION
Avatar of pramodsk40
pramodsk40
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial