.net-core - .net core 2.2 或一些代码示例中 HttpContext.Current.Session[key] 的替代品是什么
问题描述
.net core 2.2 中 HttpContext.Current.Session[key] 的替换是什么。请提供一些示例代码
解决方案
来自微软文档:
// 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);
希望能帮助到你。
推荐阅读
- python - 计算流的 Python OOP 设计模式
- c++ - 在 OOP 中处理成员依赖关系的最佳方法是什么?
- javascript - 在 Google.sites 中嵌入 Javascript
- python - Tensorflow 2.0:flat_map() 用于展平数据集的数据集返回基数 -2
- drake - Bazel 构建期间发生错误:没有这样的包'@cc//':不是常规文件:
- java - Given the above Java code fragment, SELECT the statement which identifies the number of APIs available to demonstrate dynamic polymorphism
- html - How can I center an image over a video using HTML and CSS?
- google-cloud-platform - Google Cloud SQL cross regional replication for selected schemas
- mysql - 弹簧靴。从父实体页面获取子实体页面
- android - 根据新arraylist的id更改旧arraylist中的数据