In your Startup.cs you might need to call
app.UseSession before app.UseMvc
app.UseSession();
app.UseMvc();
For this to work, you will also need to make sure the Microsoft.AspNetCore.Session nuget package is installed.
Update
You dont not need to use app.UseMvc(); in .NET Core 3.0 or higher