.Net Core 中使用Session

1、在 Startup 中 ConfigureServices 添加Session

复制代码
public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddApplicationInsightsTelemetry(Configuration);

    services.AddMvc();
    //添加Session功能
    services.AddSession();
}
复制代码

2、根据提示添加 Session 程序包

3、在 Startup 中 Configure 添加 app.UseSession();

4、简单使用

HttpContext.Session.SetString("sessionkey", "sessionvalue123");
ViewBag.SessionValue = HttpContext.Session.GetString("sessionkey");
 
分类: .Net Core
 
原文地址:https://www.cnblogs.com/webenh/p/11597602.html