当我登录应用程序时,我将我的用户名存储在 session 中,但我无法在部分页面上访问它。我试图在 Razor 部分页面上显示我的登录凭据(用户名)。我能做什么?
AppUser user = m_UserSecurity.AuthenticateUserCredentials(UserLogin.LoginID, UserLogin.Password);
HttpContext.Session.SetString("UserName", user.Name);
最佳答案
在您的 Razor 局部 View 中尝试以下代码。
@using Microsoft.AspNetCore.Http
@inject IHttpContextAccessor _httpContext
@{
var userName = _httpContext.HttpContext.Session.GetString("UserName");
}
<div>
My userName is : @userName
</div>
关于c# - 如何在asp.net core razor页面中访问部分页面中的 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75460665/