I'm trying to redirect to my home page from a page under the Areas folder.
I tried:
public IActionResult OnGet()
{
return RedirectToPage("/");
}
But this throws an exception:
System.InvalidOperationException: 'No page named '/' matches the supplied values.'
I found this question, and it recommended:
return RedirectToPage("/Index");
But this seemed to take me to the Index in the current folder.
I also tried this:
return RedirectToPage("~/Index");
But this also throws an exception:
System.InvalidOperationException: 'No page named '~/Index' matches the supplied values.'
And the same error with:
return RedirectToPage("~/");
So how can I redirect to the home page from a page under the Areas folder?
Finally figured out the answer.
return RedirectToPage("/Index", new { area = "" });
I found it rather non-intuitive.