asp.net mvc核心

编程入门 行业动态 更新时间:2024-10-22 17:30:00
本文介绍了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核心

本文发布于:2023-11-17 07:01:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609233.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:核心   asp   net   mvc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!