如何在.Net Core 2.0的Razor页面中检查用户是否已通过身份验证 [英] How to check if user is authenticated in Razor pages of .Net Core 2.0
本文介绍了如何在.Net Core 2.0的Razor页面中检查用户是否已通过身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查用户是否在Razor页面的ASP.NET Core 2.0应用程序中登录.以下代码在.NET 4.6.1中有效:
I would like to check if a user is logged in in an ASP.NET Core 2.0 application in a Razor page. The following code worked in .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中做到这一点?
How can I do this in Core 2.0?
推荐答案
编辑:大卫当然是正确的.
Edit: David is right of course.
只需检查User
或HttpContext.User.Identity.IsAuthenticated
是否为true
.
@if(!User.Identity.IsAuthenticated)
{
...
}
这篇关于如何在.Net Core 2.0的Razor页面中检查用户是否已通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文