与ViewComponent和Redis的Asp.Net Core 2问题

时间:2017-10-11 16:27:12

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

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

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

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

return RedirectToAction("Blah2");

重定向工作正常,但是当viewcomponent检查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.

1 个答案:

答案 0 :(得分:0)

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

我不得不改变

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

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

在视图组件中,有一种愚蠢的阻止。