Home > OS >  ASP.NET Core 6 How to redirect from one view to other
ASP.NET Core 6 How to redirect from one view to other

Time:08-02

tl:dr: I would love to redirect from my Layout view into an index view of a certain class. I do not want to do it through a button.

After I log in the layout page changes depending on your role. If you have a regular user role I want you to be immediately redirected to another view. This the part of the code where I would like the redirecting to take place. In the "else" clause. enter image description here

Is there a simple way about please? I was thinkig of calling a method from a controller of said class which would simply have the redirect method inside. But that has failed since I was not able to call such method simply in a view and I failed to find a way after a long google search.

Thank you for your help.

CodePudding user response:

According to your description, if you want to redirect the view from layout to another view, I suggest you could consider using the Context.Response.Redirect("~/Account/LogIn");

More details ,you could refer to below example:

@if (Context.User.Identity.IsAuthenticated)
{
    

}else
{
    Context.Response.Redirect("/home/Privacy");

}
  • Related