Environment
win7+vs2017 Purpose
Operation procedure for session asp.net using session in Core MVC
First you need to add an entry in the dependencies of the Project.json file: "Microsoft.AspNetCore.Session": "1.0.0"
Enter Startup.cs file again
Adding in the Configureservice method
Services. Addsession (Options => {
Options. IdleTimeout = Timespan.fromminutes (30);
});
Adding in the Configure method
App. Usesession ();
At this point, the session has been added to the project in a modular fashion.
The session can be read and written through the httpcontext.session in the Controller class
Call
Https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state
HttpContext.Session.SetString (Sessionkeyname, "Rick");
var name = HttpContext.Session.GetString (sessionkeyname);
. The above operation can be the session of the operation, specific if there are no Chinese characters have been tested.