To store user-specific data in ASP.Net Core web applications, we use the session state. However, using session state in ASP.Net core is not straightforward—at least, session state in ASP.Net Core doesn’t work the way it used to work in legacy ASP.Net applications. This article examines how we can work with session state in ASP.Net Core.
Create an ASP.Net Core Web API project
First off, let’s create an ASP.Net Core project and install the necessary packages. If Visual Studio 2017 is up and running in your system, follow the steps outlined below to create an ASP.Net Core Web API project.
- Launch the Visual Studio 2017 IDE.
- Click on File > New > Project.
- Select “ASP.Net Core Web Application (.Net Core)” from the list of templates displayed.
- Specify a name for the project.
- Click OK to save the project.
- Select “API” in the “New .Net Core Web Application…” window.
- Select “.Net Core” as the runtime and ASP.Net Core 2.1 (or later) from the drop-down list of controls at the top.
- Select “Web Application (Model-View-Controller)” as the project template.
- Uncheck the “Enable Docker Support” box.
- Ensure that “No Authentication” is selected as we won’t be using authentication here.
- Ensure that “Configure for HTTPS” is unchecked as we won’t need HTTPS either. (See the figure below.)
- Click OK.
This will create a new ASP.Net Core 2.1 MVC project in Visual Studio 2017.