Logout.cshtml
@page
@model BlazorGmail.Pages.Identity.LogoutModel
@{
}
Logout.cshtml.cs
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace BlazorGmail.Pages.Identity
{
public class LogoutModel : PageModel
{
public string ReturnUrl { get; private set; }
public async Task OnGetAsync(
string returnUrl = null)
{
returnUrl = returnUrl ?? Url.Content("~/");
// Clear the existing external cookie
try
{
await HttpContext
.SignOutAsync(
CookieAuthenticationDefaults.AuthenticationScheme);
}
catch (Exception ex)
{
string error = ex.Message;
}
return LocalRedirect("/");
}
}
}