我想检查用户是否在 Razor 页面的 ASP.NET Core 2.0 应用程序中登录。以下代码适用于 .NET 4.6.1:
@if (!Request.IsAuthenticated)
{
<p><a href="@Url.Action("Login", "Account")" class="btn btn1-success btn-lg" role="button" area="">Sign In »</a></p>
}
我怎样才能在 Core 2.0 中做到这一点?
Edit: 大卫当然是对的。
只需检查是否User
or HttpContext.User.Identity.IsAuthenticated
is true
or not.
@if(!User.Identity.IsAuthenticated)
{
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)