Asp.Net ViewComponent 和 Redis 的核心 2 问题

Asp.Net Core 2 issue with ViewComponent and Redis

我正在玩基本应用程序,我遇到了 Core 2.0 的问题,而我在 1.1 中没有。

该站点在 Core 2.0 上有前端和后端 api。前端的布局检查 Redis 上是否存在条目(本地安装在 Windows)以用于填充导航栏,如果不存在则调用 api,api 获取数据,用数据在redis上创建条目,return数据到前端。

直接访问视图时一切正常,但如果其中一个视图使用

return RedirectToAction("Blah2");

重定向工作正常,但是当视图组件检查 Redis 中是否存在导航栏条目时服务器挂起。观点是:

[HttpGet]
public IActionResult Blah1()
{
    return RedirectToAction("Blah2");
}

[HttpGet]
public IActionResult Blah2()
{
    return View();
}

视图组件中对Redis的检查是

var value = await _redisCache.GetAsync(userid + "-NavBar");

if (value != null)
{
    List<VMNavBar> mynavs = JsonConvert.DeserializeObject<List<VMNavBar>>(Encoding.UTF8.GetString(value));
    return View("Default", mynavs);
}
else
{
    ...
}

如果我直接访问视图 "Blah2" 它会工作,但如果我访问 "Blah1",它会阻塞 var value = await _redisCache.GetAsync(userid + " -NavBar"); 除了停止和重新启动前端应用程序外,没有任何效果。

知道为什么它只在重定向时才阻塞,或者我如何找到它阻塞的原因,我没有收到任何错误,控制台没有给我任何信息

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:55554/Dashboard/User/blah1  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:55554/Dashboard/User/blah1  
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler:Information: AuthenticationScheme: Cookies was successfully authenticated.
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler:Information: AuthenticationScheme: Cookies was successfully authenticated.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method IRDevDashboardCore22.Areas.Dashboard.Controllers.UserController.Blah1 (IRDevDashboardCore22) with arguments ((null)) - ModelState is Valid
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method IRDevDashboardCore22.Areas.Dashboard.Controllers.UserController.Blah1 (IRDevDashboardCore22) with arguments ((null)) - ModelState is Valid
Microsoft.AspNetCore.Mvc.RedirectToActionResult:Information: Executing RedirectResult, redirecting to /Dashboard/User/Blah2.
Microsoft.AspNetCore.Mvc.RedirectToActionResult:Information: Executing RedirectResult, redirecting to /Dashboard/User/Blah2.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action IRDevDashboardCore22.Areas.Dashboard.Controllers.UserController.Blah1 (IRDevDashboardCore22) in 26.7977ms
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action IRDevDashboardCore22.Areas.Dashboard.Controllers.UserController.Blah1 (IRDevDashboardCore22) in 26.7977ms
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 80.8103ms 302 
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 80.8103ms 302 
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:55554/Dashboard/User/Blah2  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:55554/Dashboard/User/Blah2  
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler:Information: AuthenticationScheme: Cookies was successfully authenticated.
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler:Information: AuthenticationScheme: Cookies was successfully authenticated.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method IRDevDashboardCore22.Areas.Dashboard.Controllers.UserController.Blah2 (IRDevDashboardCore22) with arguments ((null)) - ModelState is Valid
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method IRDevDashboardCore22.Areas.Dashboard.Controllers.UserController.Blah2 (IRDevDashboardCore22) with arguments ((null)) - ModelState is Valid
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor:Information: Executing ViewResult, running view at path /Areas/Dashboard/Views/User/Blah2.cshtml.
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor:Information: Executing ViewResult, running view at path /Areas/Dashboard/Views/User/Blah2.cshtml.

我找到了,但我不明白为什么会出现这个问题,如果我直接转到该页面,它可以工作,但如果我从另一个页面重定向到该页面,则不会。

我不得不改变

var value = await _redisCache.GetAsync(userid + "-NavBar");

var value = await _redisCache.Get(userid + "-NavBar");

在视图组件中,阻止它有点愚蠢。