?
Solved

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

Posted on 2011-02-11
2
Medium Priority
?
1,075 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 total points
ID: 34955352
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

752 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