首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >代码:在我的html文件中键入c#时“c#”无效

代码:在我的html文件中键入c#时“c#”无效
EN

Stack Overflow用户
提问于 2020-11-29 19:56:13
回答 1查看 198关注 0票数 1

我正在尝试获取cookie的值,并基于此在页面顶部的导航栏中显示不同的链接。这是一个ASP.NET Core 3.1应用程序。我收到一个错误,即单词Request在这个上下文中无效。是否有办法使该代码正常工作,还是需要不同的代码才能获得该值?在我的启动文件中,我有代码:app.UseCookiePolicy();

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-29 20:48:09

剃须刀页面有HttpContextRequestContext的一部分。

代码语言:javascript
运行
复制
@{ string signedUp = Context.Request.Cookies["signedUp"]; }

https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httpcontext.request

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65064528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档