本文介绍了asp mvc核心-等效于User.IsSignedIn()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将Web应用程序迁移到新的asp core模型上,并且突然遇到其中一种观点.
I am migrating a web application over to the new asp core model, and have hit a sudden snag with one of the views.
在新模型下,我找不到与User和User.IsSignedIn()等效的迁移对象-在视图中使用时,像这样...
I cannot find the migrated equivalent to User and User.IsSignedIn() under the new model - when used in views, like this...
@using System.Security.Claims @if (User.IsSignedIn()) { }我尝试导入Microsoft.AspNetCore.Mvc.Razor库,我认为该库将保存在该库中,但是它似乎无法以这种方式工作.
I've tried importing the Microsoft.AspNetCore.Mvc.Razor library, where I thought it would be held, but it doesn't seem to work that way.
推荐答案ASP.NET团队针对RC2采取的方法是使用SignInManager.IsSignedIn:
The approach adopted by the ASP.NET team for RC2 is to use SignInManager.IsSignedIn:
@using Microsoft.AspNetCore.Identity @using Mvc.Server.Models @inject SignInManager<ApplicationUser> SignInManager @inject UserManager<ApplicationUser> UserManager @if (SignInManager.IsSignedIn(User)) { <form asp-controller="Account" asp-action="LogOff" method="post" id="logoutForm" class="navbar-right"> <ul class="nav navbar-nav navbar-right"> <li> <a asp-controller="Manage" asp-action="Index" title="Manage">Hello @UserManager.GetUserName(User)!</a> </li> <li> <button type="submit" class="btn btn-link navbar-btn navbar-link">Log off</button> </li> </ul> </form> } else { <ul class="nav navbar-nav navbar-right"> <li><a asp-controller="Account" asp-action="Register">Register</a></li> <li><a asp-controller="Account" asp-action="Login">Log in</a></li> </ul> }更多推荐
asp.net mvc核心
发布评论