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

}

相关内容

热门资讯

第一分钟练习!wepoker免... 第一分钟练习!wepoker免费脚本(透视)确实真的是有辅助下载(哔哩哔哩)1、wepoker免费脚...
六分钟资料!hhpoker辅助... 您好,hhpoker辅助软件下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...
第三分钟指南!佛手在线大菠萝技... 第三分钟指南!佛手在线大菠萝技巧(透视)其实真的是有辅助插件(哔哩哔哩)1、该软件可以轻松地帮助玩家...
第三分钟妙计!hhpoker破... 第三分钟妙计!hhpoker破解工具(透视)总是真的是有辅助插件(哔哩哔哩)1、进入到hhpoker...
九分钟学习!pokemmo脚本... 九分钟学习!pokemmo脚本手机版(透视)竟然是真的有辅助工具(哔哩哔哩)1、进入游戏-大厅左侧-...
第五分钟方针!wepoker正... 第五分钟方针!wepoker正确养号方法(透视)确实存在有辅助透视(哔哩哔哩)1、wepoker正确...
9分钟指引!黑侠破解wepok... 9分钟指引!黑侠破解wepoker(透视)一贯真的是有辅助脚本(哔哩哔哩)黑侠破解wepoker辅助...
六分钟教材!hhpoker是内... 六分钟教材!hhpoker是内部控制吗(透视)确实存在有辅助工具(哔哩哔哩)1、玩家可以在hhpok...
四分钟手册!we poker游... 四分钟手册!we poker游戏下(透视)确实是真的有辅助教程(哔哩哔哩)1)we poker游戏下...
第5分钟大纲!hardrock... 第5分钟大纲!hardrock作必弊(透视)一贯存在有辅助安装(哔哩哔哩)1、hardrock作必弊...