Solved

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

Posted on 2011-02-11
2
1,052 Views
Last Modified: 2013-11-08
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);
        }

0
Comment
Question by:MickeC
2 Comments
 
LVL 18

Expert Comment

by:Richard Lee
ID: 34941813
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
0
 
LVL 10

Accepted Solution

by:
pramodsk40 earned 500 total points
ID: 34955352
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now