我正在使用.net core,我想访问Razor内部页面(ExternalLogin.CS.html)中当前登录的User属性,并且基于用户属性我想重定向到其他页面。但是我无法访问剃刀页面中的用户。
public async Task<IActionResult> OnGetCallbackAsync(string returnUrl = null, string remoteError = null)
{
returnUrl = returnUrl ?? Url.Content("~/");
if (remoteError != null)
{
ErrorMessage = $"Error from external provider: {remoteError}";
return RedirectToPage("./Login", new {ReturnUrl = returnUrl });
}
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
ErrorMessage = "Error loading external login information.";
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
}
// Sign in the user with this external login provider if the user already has a login.
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent:false, bypassTwoFactor : true);
if (result.Succeeded)
{
//if (user.verifiedPhone)
//{
// return LocalRedirect("/Identity/Account/Manage");
//}
_logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider);
return LocalRedirect("/Customer/ProjectsApiKey/");
}
if (result.IsLockedOut)
{
return RedirectToPage("./Lockout");
}
我已经厌倦了回答相同问题的一些答案,但是在.net核心Move中。它不适用于我的Razor页面。
var user = _userManager.GetUser(HttpContext.User);
请提出任何建议,以访问剃刀内的当前登录用户