I am getting error as "object reference not set to an instance of an object httpcontext.current.session".
            Asked
            
        
        
            Active
            
        
            Viewed 5,123 times
        
    -5
            
            
        - 
                    The field you are trying to check in session does not exist yet. – Amit Kumar Singh Oct 16 '17 at 06:43
- 
                    I want to use session value throughout the application including class library. – Vishal Shira Oct 16 '17 at 06:44
- 
                    search "httpcontext.current.session web api" on google. you'll find the answer yourself. – Tsahi Asher Oct 16 '17 at 07:01
1 Answers
1
            First you should get knowledge of Session.
Before retrieving HttpContext.Current.Session follow following steps.
- Set Session Value: - HttpContext.Current.Session["ID"] = value;
- 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
