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 580477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:28:38+00:00 2026-05-13T14:28:38+00:00

I have 2 projects in my solution. MVC Web application Class library The MVC

  • 0

I have 2 projects in my solution.

  1. MVC Web application
  2. Class library

    • The MVC Web application references the class library.
    • The class library contains a class that extends the default ASP.Net Controller.

I’m putting a variable in session in the application’s Global.asax.

protected void Session_Start(object sender, EventArgs args)
{
   HttpContext.Current.Session["DomainName"] = Request.Url.Host;
}

In the class library I’m trying to get the value from the HttpContext.Session, but HttpContext.Session keeps coming up null.

public class MyController : System.Web.Mvc.Controller
{
    public MyController () : base()
    {
        //HttpContext.Session is always null at this point
        ViewData["DomainName"] = HttpContext.Session["DomainName"];
    } 
}

HttpContext.Current.Session doesn’t seem to be an option in controllers. Any ideas?

  • 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-05-13T14:28:39+00:00Added an answer on May 13, 2026 at 2:28 pm

    Two issues — the HttpContext property in the Controller class is the current session. Unfortunately, it’s not available in the constructor of the controller. Obviously because it’s not passed in the constructor, it has to be set via the property afterwards. You might consider adding a property to hold the domain name and referencing the session from it — that way it would be available for use when needed.

     protected string DomainName
     {
          get { return this.HttpContext.Session["DomainName"] as string; }
     }
    

    The set it in ViewData in your actions or in OnActionExecuting/OnActionExecuted.

     protected override void OnActionExecuted( ActionExecutedContext context )
     {
          ViewData["DomainName"] = this.HttpContext.Session["DomainName"];
          // or ViewData["DomainName"] = this.DomainName;  // if you used the property
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Bootstrapper that looks through all Assemblies in an ASP.NET MVC application
I have several projects and a website in a large asp.net solution. In some
I have several web application projects in one solution. When I start debugging one
We have a Visual Studio 2010 solution that contains several C# projects in accordance
I have 3 projects in my solution that I want to deploy. Is there
I have 3 projects in my solution that I want to deploy. Is there
I have a solution containing several projects that have migrated from VS 2003, 2005,
I have a number of projects in a solution file that have unit tests
My ASP.NET MVC 2 application uses Entity Framework 4.0 for the data model. Following
I'm working in VS 2008 and have three projects in one solution. I'm debugging

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.