Logout.cshtml.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Threading.Tasks;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Identity;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Mvc.RazorPages;
  6. using Microsoft.Extensions.Logging;
  7. namespace BO.AppServer.Web.Areas.Identity.Pages.Account
  8. {
  9. [AllowAnonymous]
  10. public class LogoutModel : PageModel
  11. {
  12. private readonly SignInManager<IdentityUser> _signInManager;
  13. private readonly ILogger<LogoutModel> _logger;
  14. public LogoutModel(SignInManager<IdentityUser> signInManager, ILogger<LogoutModel> logger)
  15. {
  16. _signInManager = signInManager;
  17. _logger = logger;
  18. }
  19. public void OnGet()
  20. {
  21. }
  22. public async Task<IActionResult> OnPost(string returnUrl = null)
  23. {
  24. await _signInManager.SignOutAsync();
  25. _logger.LogInformation("User logged out.");
  26. if (returnUrl != null)
  27. {
  28. return LocalRedirect(returnUrl);
  29. }
  30. else
  31. {
  32. return RedirectToPage();
  33. }
  34. }
  35. }
  36. }