1.使用Session(进程内)

在startup中添加方法 services.AddSession  app.UseSession()

 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");

示例:

.Netcore使用Session

使用方式: 

 HttpContext.Session.SetString("key", “value”);  //设置

HttpContext.Session.GetString("key");//获取session

4.使用Sqlserver数据库存储Session

services.AddDistributedSqlServerCache

 

参考:

ASP.NET Core中间件实现分布式 Session: https://www.cnblogs.com/vipyoumay/p/7771237.html

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-27
  • 2021-05-30
  • 2021-10-02
  • 2022-02-09
  • 2021-09-15
  • 2022-02-16
  • 2022-01-22
相关资源
相似解决方案