我需要将 MVC 项目迁移到 .net Core,我知道它已从 ASP.net Core 中删除了 System.Web。我需要转换 HttpContext.Current.Session [“name”]!= 在 ASP.NET Core 中为 Null。我添加:使用 Microsoft.AspNetCore.Http 但出现错误。
像这样使用:
HttpContext.Session.SetString("priceModel", JsonConvert.SerializeObject(customobject));
var priceDetails = HttpContext.Session.GetString("priceModel");
Run Code Online (Sandbox Code Playgroud)
在启动类中确保以下几点:
在ConfigureServices方法中添加Session
services.AddSession();
Run Code Online (Sandbox Code Playgroud)
配置方法中的使用会话:
app.UseSession();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20703 次 |
| 最近记录: |