I am using .net core and I want to access current logged in User property in Inside a Razor page (ExternalLogin.CS.html) and based on user property I want to redirect to different pages.But I am unable to access the user inside the razor page.

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");

I have tired some answers that are answered for same question but in .net core Move .it's not worked for my Razor pages.

var user = _userManager.GetUser(HttpContext.User);

please give any Suggestions to access current loged-In User inside a Razor

Related posts

Recent Viewed