原文地址:https://www.cnblogs.com/wtujvk/p/8743035.html
ASP.NET Core 保存Session的方法:a.内存方式,b.Redis,c.Redis集群,d.SqlServer
1.使用Session(进程内)
在startup中添加方法
-
services.AddDistributedMemoryCache();
-
-
-
-
-
-
2.使用Redis存储Session(单节点)
-
services.AddDistributedRedisCache(option => {
-
-
option.Configuration = “127.0.0.1:6379”;
-
option.InstanceName = 30;
-
3.使用Redis分布式存储 (分布式)
nuget: Microsoft.AspNetCore.DataProtection
-
services.AddDataProtection()
-
.SetApplicationName(Configuration["Redis:Session_application_name"])
-
.PersistKeysToRedis(ConnectionMultiplexer.Connect(redisconfig), "DataProtection-Keys");
示例:

使用方式:
-
HttpContext.Session.SetString("key", “value”);
-
-
HttpContext.Session.GetString("key");
4.使用Sqlserver数据库存储Session
services.AddDistributedSqlServerCache
asp.net core的 session存储
原文:https://www.cnblogs.com/sunalways/p/13260696.html