I need to know how to redirect a user if they are signed in to my app. There are 2 parts to my problem:
- Set the default page to /Account/Login
- If the user is already signed in (Remember Me check box is checked), then redirect to
BookDetails.cs
controller
I have already solved problem 1 by adding the following code to Program.cs
:
builder.Services.AddControllersWithViews().AddRazorPagesOptions(options => { options.Conventions.AddAreaPageRoute("Identity", "/Account/Login", "")})
I know how to check if the user is currently signed in. If I wanted to check if the user is currently signed in from BookDetailsController
I would include the following code in the controller file:
...
private readonly SignInManager<IdentityUser> _signInManager;
public BookDetailsController(BookClubBookDetailsContext context, SignInManager<IdentityUser> signInManager)
{
_signInManager = signInManager;
_context = context;
}
...
How do I redirect from Login page if the user is already logged in?
Edit:
Here is my problem described visually: