ASP.NET状态服务在.NET6中未能工作。
创始人
2024-09-19 23:00:57
0

在 .NET6 中,ASP.NET 状态服务已被弃用。替代方案是使用 Microsoft.Extensions.Caching 和 Microsoft.Extensions.Caching.SqlServer 包来管理应用程序状态。以下是使用此替代方案的代码示例:

  1. 在 Startup.cs 文件中,添加以下代码:

services.AddDistributedSqlServerCache(options => { options.ConnectionString = Configuration.GetConnectionString("SqlServerCache"); options.SchemaName = "dbo"; options.TableName = "TestCache"; });

  1. 在 appsettings.json 文件中,添加以下代码:

"ConnectionStrings": { "SqlServerCache": "" }

  1. 在需要使用应用程序状态的地方,可以注入 IDistributedCache 接口来设置和获取状态。例如:

private readonly IDistributedCache _cache;

public HomeController(IDistributedCache cache) { _cache = cache; }

public IActionResult Index() { var value = _cache.GetString("testKey"); if (value == null) { value = "testValue"; _cache.SetString("testKey", value); }

ViewData["cachedValue"] = value;

return View();

}

相关内容

热门资讯

透视好友!hhpoker德州机... 透视好友!hhpoker德州机器人,hhpoker到底可以辅助吗,攻略教程(有挂规律)-哔哩哔哩1、...
透视智能ai!wepoker破... 透视智能ai!wepoker破解器,哈糖大菠萝挂,步骤教程(有挂细节)-哔哩哔哩暗藏猫腻,小编详细说...
透视系统!aapoker脚本,... 透视系统!aapoker脚本,wepoker辅助器安装包定制,窍要教程(揭秘有挂)-哔哩哔哩1)we...
透视挂!智星德州插件,wepo... 透视挂!智星德州插件,wepoker有没有辅助,资料教程(有挂教程)-哔哩哔哩1、游戏颠覆性的策略玩...
透视苹果版!pokemmo脚本... 透视苹果版!pokemmo脚本辅助器,we poker免费辅助器,秘籍教程(有挂分享)-哔哩哔哩1、...
透视能赢!wepoker能不能... 透视能赢!wepoker能不能透视,hhpoker德州挂真的有吗,要领教程(详细教程)-哔哩哔哩1、...
透视好牌!wpk透视是真的假的... 透视好牌!wpk透视是真的假的,wepoker游戏的安装教程,教程书教程(有挂技巧)-哔哩哔哩一、w...
透视科技!wpk辅助插件,wp... 透视科技!wpk辅助插件,wpk透视插件,手册教程(证实有挂)-哔哩哔哩wpk辅助插件辅助器中分为三...
透视能赢!hhpoker辅助靠... 透视能赢!hhpoker辅助靠谱吗,wepoker怎么设置房间,手段教程(有挂技巧)-哔哩哔哩1、让...
透视好友!wpk刷入池率脚本,... 透视好友!wpk刷入池率脚本,wepoker免费透视,操作教程(有挂技巧)-哔哩哔哩wpk刷入池率脚...