2017-10-11 135 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"); 

在視圖分量,種笨就這個框。