我正在尝试获取Cookie的值,并根据该值在页面顶部的导航栏中显示不同的链接。这是一个ASP.NET Core MVC 3.1应用程序。我收到一个错误,该词Request
在此上下文中无效。有没有办法使该代码正常工作,还是需要其他代码才能获得该价值?在我的启动文件中,我有以下代码:app.UseCookiePolicy();
<li class="nav-item">
@{string signedUp = Request.Cookies["signedUp"]; }
@*if user's first time, show signup link, otherwise, then the if else below...*@
@if (User.Identity.IsAuthenticated)
{
<a class="nav-link text-dark" asp-area="" asp-controller="Account" asp-action="LogOut">Log Out</a>
}
else
{
<a class="nav-link text-dark" asp-area="" asp-controller="Account" asp-action="LogIn">Log In</a>
}
</li>
剃须刀页面具有HttpContext
和,它们Request
是的一部分Context
:
@{ string signedUp = Context.Request.Cookies["signedUp"]; }
https://docs.microsoft.com/zh-cn/dotnet/api/microsoft.aspnetcore.http.httpcontext.request