asp.net core Use session

Source: Internet
Author: User
Tags httpcontext
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.