Software developer can interact with session state using the  System.Web.SessionState.HttpSessionState class, which is provided in an ASP.NET web page as the built-in Session object. Items can be added to the collection and retrieved after in the same manner as items can be added to a page’s view state:

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development: Build applications with C#, .NET Core, Entity Framework Core, ASP.NET Core, and ML.NET using Visual Studio Code, 4th Edition
ASP.NET Core 3 and Angular 9: Full stack web development with .NET Core 3.1 and Angular 9, 3rd Edition
C# in Depth, 4th Edition

For example, software developer might store a string in memory like this:

Session[“FirstName”] = firstName;

Then he can retrieve it with an appropriate conversion operation:

firstName = (string)Session[“FirstName”];

Session state is global to entire web application for the current user. The session state can be lost if:

–          The user closes and restart the browser
–          The user accesses the same page through a different browser window. Browsers differ on how handle situation like this.
–          The session times out due to inactivity.
–          The developer ends the session in code.

In the first two cases, the session remains in memory, because the web server “does not know” that the client has closed the browser or change windows. The session will stay in memory, remaining inaccessible, until it expires.