【发布时间】:2020-06-15 00:21:12
【问题描述】:
我使用的是 ASP.NET Core 3.1。 我需要在控制器的动作中设置一个会话。我在 ConfigureServices() 方法中添加了会话:
services.AddSession(options => {
options.IdleTimeout = System.TimeSpan.FromSeconds(3600);
});
我还添加了在 Configure() 方法中使用会话的代码:
app.UseSession();
在控制器类中我试图创建一个会话
HttpContext.Session.Set("sessionuser",xxx);
所需的 xxx 是一个字节[],这与 .NET CORE 2.2 中的 SetString() 中所需的字符串不同 如何为此创建字节[]?创建会话还有其他更好的选择吗?
【问题讨论】:
-
How to create the byte[] for this是什么意思,如果您需要字符串,只需使用HttpContext.Session.SetString()并添加对Microsoft.AspNetCore.Http;的引用
标签: c# asp.net-core session .net-core