asp.net-core - 如何在 ASP.NET Core 中获取 HttpContext.Current.Session?
问题描述
我需要将 MVC 项目迁移到 .net Core,我知道它已从 ASP.net Core 中删除了 System.Web。我需要转换 HttpContext.Current.Session ["name"]!= 在 asp.net 核心处为空。我补充说:使用 Microsoft.AspNetCore.Http 但我有一个错误。
解决方案
像这样使用:
HttpContext.Session.SetString("priceModel", JsonConvert.SerializeObject(customobject));
var priceDetails = HttpContext.Session.GetString("priceModel");
确保启动类中的以下几点:
ConfigureServices 方法中的 AddSession
services.AddSession();
在配置方法中使用会话:
app.UseSession();
推荐阅读
- windows - Dockerfile vs 从容器创建镜像
- excel - SSRS Excel 导出。多标签
- python - Openpyxl Pip 安装错误:命令出错
- r - R data.table 有条件地按组聚合行
- javascript - 如何在没有 try/catch 块的情况下使用异步 lambda 并且仍然有自定义错误消息?
- sql - 你将如何在 Ruby 中替换这个 SQL 查询,以便只使用 ActiveRecord 代码?
- c - 我想将客户信息存储在一系列客户中
- database - 如何将包含所有数据的架构导出到我的 PC 上的本地实例 (Oracle XE)
- git - 有没有办法将最新的 git 日志添加到提交中?
- python - 在包含字符串的python矩阵中查找最大数的索引