[英]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.