-5

I am getting error as "object reference not set to an instance of an object httpcontext.current.session".

Vishal Shira
  • 3
  • 1
  • 2

1 Answers1

1

First you should get knowledge of Session.

Before retrieving HttpContext.Current.Session follow following steps.

  1. Set Session Value:

    HttpContext.Current.Session["ID"] = value;
    
  2. Get Session Value:

    var value = HttpContext.Current.Session["ID"];
    

Be confirm you have derived System.Web.dll reference in your project Reference

You will get error = "Object reference not set...." when key in Session["ID"] not matched and this is case sensitive.

Aleks Andreev
  • 7,016
  • 8
  • 29
  • 37
Dave
  • 36
  • 5
  • I have done above code. However, i was still facing the same issue. In order to solve the problem, i have added below functions in Global.asax.cs file and the issue was resolved. public override void Init() { this.PostAuthenticateRequest += MvcApplication_PostAuthenticateRequest; base.Init(); } void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e) { System.Web.HttpContext.Current.SetSessionStateBehavior( SessionStateBehavior.Required); } – Vishal Shira Oct 23 '17 at 05:50