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

  • SEARCH
  • Home
  • 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 7873061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:24:00+00:00 2026-06-03T02:24:00+00:00

New to SPA MVC4, trying to pass a session variable to LinqToEntitiesDataController from the

  • 0

New to SPA MVC4, trying to pass a session variable to LinqToEntitiesDataController from the account controller to identify the user by:

                      using (DALEntities db = new DALEntities())
                        {
                            string PHN = (from p in db.Patients
                                          where p.UserName == model.UserName
                                          select p.PHN).First();
                            Session["P"] = PHN;
                        }

In the LinqToEntitiesDataController I am trying to use the variable as follows:

public partial class DALController : LinqToEntitiesDataController<MyVDC.Models.DALEntities>
    {
        public IQueryable<MyVDC.Models.TestModel> GetTestModel()
        {
            **string phn = (string)Session["P"];**
            return ObjectContext.TestModels.Where(b => b.PHN == phn).OrderBy(b => b.ID);

        }
}

I get this Error:

The name 'Session' does not exist in the current context

Is this the only way, or is there a better method to use the session variables with this controller.

I also tried to use in the account controller:

 HttpContext.Current.Session["P"] = PHN;

But I get this error:

'System.Web.HttpContextBase' does not contain a definition for 'Current' and no extension method 'Current' accepting a first argument of type 'System.Web.HttpContextBase' could be found 

Thanks in advance.

  • 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-03T02:24:02+00:00Added an answer on June 3, 2026 at 2:24 am
    public class SessionHttpControllerRouteHandler : HttpControllerRouteHandler
    {
        protected override IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestContext)
        {
            return new SessionHttpControllerHandler(requestContext.RouteData);
        }
    }
    
    public class SessionHttpControllerHandler : HttpControllerHandler, IRequiresSessionState
    {
        public SessionHttpControllerHandler(RouteData routeData) : base(routeData) { }
    }
    

    Create session support HttpControllerHandler, and route entry this class in Global.asax.

        routes.Add("SessionApis",
            new HttpWebRoute(
                url: "api/{controller}/{id}",
                defaults: new RouteValueDictionary(new {id = RouteParameter.Optional}),
                routeHandler: new SessionHttpControllerRouteHandler()
        ));
    

    But, I think ApiController is good to use by sessionless. so scalable and REST principle.

    LinqToEntitiesDataController route add at Custom AreaRegistration class( DALRouteRegistration class?).
    Change scaffolding default area register code.

    from

        RouteTable.Routes.MapHttpRoute(
            "DAL", // Route name
            "api/DAL/{action}", // URL with parameters
            new { controller = "DAL" } // Parameter defaults
        );
    

    to

        RouteTable.Routes.Add("SessionDALApis",
            new HttpWebRoute(
                url: "api/DAL/{action}",
                defaults: new RouteValueDictionary(new { controller = "DAL" }),
                routeHandler: new SessionHttpControllerRouteHandler()
        ));
    

    How about this?

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

Sidebar

Related Questions

New to SharePoint. I'm trying to upload a document to SharePoint using it's CopyIntoItems
I'm trying to read input from the terminal. For this, I'm using a BufferedReader.
New to javascript - I'm trying to generate random user ID's for my selenium
New to javascript/jquery and having a hard time with using this or $(this) to
I'm trying to make a form to login users into my webpage using mysql
new AjaxOptions { OnBegin = MyFunction, Url=/Controller/JSONAction/+OnbeginRetunrValue, HttpMethod=GET } In my Ajax properties, I
Just trying out the sample for the MVC4 Single Page Application. The BigShelf project
New to Python and trying to figure out what went wrong here. Making a
New to R, and am trying to install the text mining package (tm). However
New to REgEX and in my sixties so bear with me Using ColdFusion so

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.