Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect controller to razor page in area section asp Core 2.1

I want to redirect from my controller to a razor page that's in an area section. My controller user is restricted if the user is null then redirects to the login page in Area/Identity/Pages/Account/login.cshtml.

My Controller:

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

                return RedirectToPage("Login");
            }

How do I write a return line to redirect to my login page using asp.net core 2.1.

like image 944
Jagdish Kumar Avatar asked Sep 28 '18 16:09

Jagdish Kumar


2 Answers

Use this line to redirect to page from controller action

return LocalRedirect("/Identity/Account/Login");
like image 178
Zubair Rana Avatar answered Nov 23 '22 18:11

Zubair Rana


This works too:

return RedirectToPage("/Account/Login", new { area = "Identity" });

tested in asp.net core 2.2

like image 34
HO3EiN Avatar answered Nov 23 '22 17:11

HO3EiN