How to use (get and set) httpcontext.current.Session in the class library, within MVC web api application? [duplicate]

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.

Browse More Popular Posts

Leave a Comment