I am building a web application using the ASP.NET Core 3.1 MVC and Razor pages.
I am new to Razor pages.
I created a basic application using above. I want to load the Login page on start of the application but the Index.cshtml page seems to be the start page.
To redirect from the Index.cshtml page (start page) to my Login.cshtml page, I did following in the Index.cshtml PageModel. But it is not working.
EDITED:
Index.cshtml:
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<form method="get" asp-page="Index" hidden name="myForm">
<input type="submit" name="submit" value="Redirect 1" asp-page-handler="Redirect1" hidden />
</form>
</div>
Index.cshtml.cs:
public class IndexModel : PageModel
{
public IndexModel()
{
OnPostRedirect1();
}
public void OnGet() {}
public IActionResult OnPostRedirect1()
{
return RedirectToPage("Login");
}
}
How to automatically redirect to Login page from Index page?