【问题标题】:Asp.Net Core 2 issue with ViewComponent and RedisViewComponent 和 Redis 的 Asp.Net Core 2 问题
【发布时间】:2017-10-14 07:04:03
【问题描述】:

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

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

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

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.

【问题讨论】:

    标签: asp.net-core asp.net-core-mvc asp.net-core-2.0


    【解决方案1】:

    我找到了它,但我不明白为什么会这样

    我不得不改变

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      • 2021-06-11
      • 1970-01-01
      相关资源
      最近更新 更多