我正在尝试获取cookie的值,并基于此在页面顶部的导航栏中显示不同的链接。这是一个ASP.NET Core 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>发布于 2020-11-29 20:48:09
剃须刀页面有HttpContext,Request是Context的一部分。
@{ string signedUp = Context.Request.Cookies["signedUp"]; }https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httpcontext.request
https://stackoverflow.com/questions/65064528
复制相似问题