Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7797277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:38:09+00:00 2026-06-01T23:38:09+00:00

I created an ApplicationController.cs that all other Controllers inherit. I’m trying to use this

  • 0

I created an ApplicationController.cs that all other Controllers inherit. I’m trying to use this Controller to capture the user’s full name from the DB, set to ViewBag & capture in layout.cshtml.

I aslo created a session variable in Global.asax that captures the user’s login. My problem is that the Session variable is null in ApplicationController.cs. However, the session variable is populated properly in all the children Controllers. Here’s my ApplicationController.cs code:

public abstract class ApplicationController : Controller
{
    private SkadPROEntities db = new SkadPROEntities();

    public SkadPROEntities SkadProDB
    {
        get { return db; }                
    }


    public ApplicationController()
    {
        //string[] currentUserString = User.Identity.Name.Split('\\');
        //string myCurrentUser = currentUserString[1];
        //string myCurrentUser = Session["currentUser"].ToString();
        var empQuery = from employee in db.PRO_LSN_EMPLOYEE_OBJ
                       //where employee.LSN_Security_Nbr == Session["currentUser"].ToString()
                       where employee.LSN_Security_Nbr == "bhopkins"
                       select employee;
        string firstName = "";
        foreach (var myEmployee in empQuery)
        {
            firstName = myEmployee.LSN_cf_First_Name;
        }
        ViewBag.FirstName = firstName;
        ViewBag.EmpName = "Bill Test";
    } 
}

Why is the session variable null in ApplicationController.cs, but populated in all the children Controllers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:38:11+00:00Added an answer on June 1, 2026 at 11:38 pm

    You can’t access session variables in constructors. Presumably you’re trying to access the session variable within the actions of your children constructors, not their constructors.

    See Session null in ASP.Net MVC Controller Constructors

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all,(im a beginner in rails) i've created a controller that look like that:
I created a cursor from the one that was described on this post: SQL
Hy, I was thinking that all my website will have use of cells, using
I have this relationship where User can create a document(trip) and invite other users
I have this controller: class AlexesController < ApplicationController # GET /alexes # GET /alexes.json
I'm trying to show all messages that belong to each channel on that channels
I have a couple of variables that need to be called in all controllers.
Created an OpenGraph action and object. Trying to submit my action. When I click
I created an AMP web application that was originally going to be served from
I have an application that tracks services (servers) with IP addresses. I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.