2017-10-11 100 views
1

我正在玩基本的应用程序,我遇到了核心2.0的问题,我没有在1.1中。Asp.Net核心2与ViewComponent和Redis问题

该网站在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. 

回答

0

,我发现它和我做的任何想法不明白为什么它是这个问题,如果我直接进入它的工作页面,但不是如果我被重定向到另一个页面。

我不得不改变

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

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

在视图分量,种笨就这个框。