简体   繁体   English

从 .net4.8 升级后 .net6 中的会话

[英]Sessions in .net6 after upgrading from .net4.8

I just upgraded my .net 4.8 MVC web app to .net6.我刚刚将我的 .net 4.8 MVC web 应用程序升级到 .net6。 I used Sessions to store objects.我使用 Sessions 来存储对象。 for example the User class:例如用户 class:

public class User
{
    [Key]
    public string UserID { get; set; }
    public string TenantId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string MobilePhone { get; set; }
    public bool IsEnabled { get; set; }
    public virtual ICollection<Department> Departments { get; set; }

}

This is how I set the session:这就是我设置 session 的方式:

Session[Consts.CURRENTUSER] = userFromDb;

This is how I use it:这就是我使用它的方式:

User _currentUser = Session[Consts.CURRENTUSER] as User;

Now, after the upgrade it does not compile.现在,升级后它不会编译。 I get the following error:我收到以下错误:

Error CS0103 The name 'Session' does not exist in the current context错误 CS0103 当前上下文中不存在名称“会话”

If i use the following HttpContext.Session[Consts.CURRENTUSER] as User it still does not allow the the above use.如果我使用以下HttpContext.Session[Consts.CURRENTUSER] as User ,它仍然不允许上述使用。

Will appreciate an example on how I will be able to use the above scenario in .net core.将了解如何在 .net 内核中使用上述场景的示例。

after reading Microsoft docs , I followed this guide from step 4 to allow the usage of Sessions.阅读Microsoft 文档后,我从第 4 步开始按照本指南允许使用 Sessions。 Then, in order to use complex objects in .net core I followed this link which provided an extension method that implementing the use of complex objects in sessions.然后,为了在 .net 内核中使用复杂对象,我点击了这个链接,它提供了一个扩展方法,实现了在会话中使用复杂对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HttpClient HttpRequestMessage 在 net6 中失败,但在 net4.8 中有效 - HttpClient HttpRequestMessage fails in net6 but works in net4.8 从 .Net 4.6.1 升级到 .Net 4.8 后使用 System.IO.Compression 的问题 - Problems using System.IO.Compression after upgrading from .Net 4.6.1 to .Net 4.8 从 .NET Framework 4.8 升级到 .NET 5 后无法使用 WSFederation 进行身份验证 - Unable to authenticate using WSFederation after upgrading to .NET 5 from .NET Framework 4.8 .NET 4.8 webapi 迁移到 .net6 时出现 WrongEnum 值问题 - .NET 4.8 webapi migrate to .net6 issue with WrongEnum value 从 .Net Framework 4.7 升级到 4.8 后使用 MSBuild 发布项目时出错 - Error in publishing project with MSBuild after upgrading from .Net Framework 4.7 to 4.8 从 .NET Framework 4.5.2 升级到 4.8 后,带有 COM 初始化的 Windows 服务不再工作 - Windows service with COM initialization is not working any more after upgrading from .NET Framework 4.5.2 to 4.8 C# WPF.Net4.8 框架只读TextBox文本绑定延迟更新 - C# WPF .Net4.8 Framework ReadOnly TextBox Text Binding Delayed Update 从 .net6 升级到 .net7 Rc1 时违反了类型“T”的约束 - violates the constraint of type 'T' when upgrading from .net6 to .net7 Rc1 在 WPF 上从 .NET5 升级到 .NET6 后开始调试失败 - Start with Debugging fails after upgrade from .NET5 to .NET6 on WPF 为什么 builder.Use 在从 net5 迁移到 net6 后不起作用? - Why builder.Use is not working after migrating from net5 to net6?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM