I have declared Session variable in "Global.asax" file as,
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
int temp=4;
HttpContext.Current.Session.Add("_SessionCompany",temp);
}
And want to use this Session Variable into My Controller's action as,
public ActionResult Index()
{
var test = this.Session["_SessionCompany"];
return View();
}
But I am Getting Exception While accessing the Session Variable.
Please help me on this that How can I access the Session Variable into my controller's Action.
I am getting an Exception like
"Object Reference not set to an Insatance of an object"
in Application_Start
in Global.asax on line
HttpContext.Current.Session.Add("_SessionCompany",temp);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…