有没有办法使用 ASP.NET Core MVC 配置进程外 session 状态(使用 Windows 状态服务器或 SQL Server)?
最佳答案
重要的是 session 数据由缓存支持。您需要将 IDistributedCache 实现添加到您的应用程序服务,而不是内存缓存,即:
对于 SQL Server:
services.AddDistributedSqlServerCache(options =>
{
options.ConnectionString = @"your_connection_string";
options.SchemaName = "dbo";
options.TableName = "TestCache";
});
(确保您的项目中添加了 Microsoft.Extensions.Caching.SqlServer
包)
对于 Redis:
services.AddDistributedRedisCache(options =>
{
options.Configuration = "localhost";
options.InstanceName = "SampleInstance";
});
(包:Microsoft.Extensions.Caching.Redis
)
我不知道是否有针对 ASP.NET Core 分布式缓存的 Windows State Server 的实现。
分布式 session 的文档链接:https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed
有关 ASP.NET Core 中 session 的更多信息:https://learn.microsoft.com/en-us/aspnet/core/fundamentals/app-state
关于asp.net-core - ASP NET Core MVC - 如何配置进程外 session 状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38536012/