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.
Create session support HttpControllerHandler, and route entry this class in Global.asax.
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
to
How about this?