I have made razor page to log out users. When authenticated user visits route /account/logout I want to show him the page with success message, if user is anonymous then page is unathorized. However this success page must not be accessible by direct url input.
Following code works well except anyone can navigate to /account/logout/success which acts as normal page (and since it's not one responsible for signing out, it's potentially confusing).
public class LogoutModel : CustomPageModel
{
private readonly SignInManager _signInManager;
public LogoutModel(SignInManager signInManager) => _signInManager = signInManager;
public async Task<IActionResult> OnGetAsync()
{
if (_signInManager.IsSignedIn(User))
{
await _signInManager.SignOutAsync();
return RedirectToPage("Logout", "Success");
}
return Unauthorized();
}
public void OnGetSuccess()
{
}
}
How do I prevent handler OnGetSuccess to be accessible directly?