如何将控制器重定向到区域部分ASP Core 2.1中的剃须刀页面

Jag*_*mar 1 asp.net-core-2.1

我想从控制器重定向到区域区域中的剃须刀页面。如果用户为null,则将限制我的控制器用户,然后重定向到中的登录页面Area/Identity/Pages/Account/login.cshtml

我的控制器:

var user = await _userManager.GetUserAsync(User);
            if (user == null)
            {
                //return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");

                return RedirectToPage("Login");
            }
Run Code Online (Sandbox Code Playgroud)

如何编写返回行以使用重定向到我的登录页面asp.net core 2.1

Zub*_*ana 8

使用此行从控制器操作重定向到页面

return LocalRedirect("/Identity/Account/Login");
Run Code Online (Sandbox Code Playgroud)


Hos*_*aei 5

这也有效:

return RedirectToPage("/Account/Login", new { area = "Identity" });
Run Code Online (Sandbox Code Playgroud)

在asp.net core 2.2中测试