首页 > 解决方案 > .net core 2.2 或一些代码示例中 HttpContext.Current.Session[key] 的替代品是什么

问题描述

.net core 2.2 中 HttpContext.Current.Session[key] 的替换是什么。请提供一些示例代码

标签: .net-core

解决方案


来自微软文档

// Requires: using Microsoft.AspNetCore.Http;

HttpContext.Session.SetString(SessionKeyName, "The Doctor");
HttpContext.Session.SetInt32(SessionKeyAge, 773);

var name = HttpContext.Session.GetString(SessionKeyName);
var age = HttpContext.Session.GetInt32(SessionKeyAge);

希望能帮助到你。


推荐阅读