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

Ask A Question

Stats

  • Questions 305k
  • Answers 305k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try something like: import-module ExpressionEncoder ls | Convert-Media -VC1IISSmoothStreamingSD480pVBR -TemplateBlackGlass… May 13, 2026 at 9:07 pm
  • Editorial Team
    Editorial Team added an answer The crash is due to delegate getting release by the… May 13, 2026 at 9:07 pm
  • Editorial Team
    Editorial Team added an answer Never mind got the answer from below link text May 13, 2026 at 9:07 pm

Related Questions

Until the preview release yesterday of ASP.NET MVC I had been desperately needing a
Here is my situation: I have a solution with three projects: 1) Silverlight App,
I'm building an ASP.Net MVC website. Rather than have everything in one project, I've
I have a solution with two relevant (to this question) projects, and a few
I'm writing this question from the standpoint of an ASP.NET application. However I realize

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.