diff --git a/src/Web/Areas/Identity/Pages/Account/Logout.cshtml b/src/Web/Areas/Identity/Pages/Account/Logout.cshtml new file mode 100644 index 0000000..cb864ef --- /dev/null +++ b/src/Web/Areas/Identity/Pages/Account/Logout.cshtml @@ -0,0 +1,10 @@ +@page +@model LogoutModel +@{ + ViewData["Title"] = "Log out"; +} + +
+

@ViewData["Title"]

+

You have successfully logged out of the application.

+
\ No newline at end of file diff --git a/src/Web/Areas/Identity/Pages/Account/Logout.cshtml.cs b/src/Web/Areas/Identity/Pages/Account/Logout.cshtml.cs new file mode 100644 index 0000000..ee12cbc --- /dev/null +++ b/src/Web/Areas/Identity/Pages/Account/Logout.cshtml.cs @@ -0,0 +1,41 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.eShopWeb.Infrastructure.Identity; +using Microsoft.Extensions.Logging; + +namespace Microsoft.eShopWeb.Web.Areas.Identity.Pages.Account +{ + [AllowAnonymous] + public class LogoutModel : PageModel + { + private readonly SignInManager _signInManager; + private readonly ILogger _logger; + + public LogoutModel(SignInManager signInManager, ILogger logger) + { + _signInManager = signInManager; + _logger = logger; + } + + public void OnGet() + { + } + + public async Task OnPost(string returnUrl = null) + { + await _signInManager.SignOutAsync(); + _logger.LogInformation("User logged out."); + if (returnUrl != null) + { + return LocalRedirect(returnUrl); + } + else + { + return RedirectToPage("/Index"); + } + } + } +} \ No newline at end of file diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index dc4a91f..daac6b1 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -174,7 +174,7 @@ namespace Microsoft.eShopWeb.Web options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromHours(1); options.LoginPath = "/Account/Login"; - options.LogoutPath = "/Account/Signout"; + options.LogoutPath = "/Account/Logout"; options.Cookie = new CookieBuilder { IsEssential = true // required for auth to work without explicit user consent; adjust to suit your privacy policy @@ -236,10 +236,6 @@ namespace Microsoft.eShopWeb.Web app.UseMvc(routes => { - routes.MapRoute( - name: "identity", - template: "Identity/{controller=Account}/{action=Register}/{id?}"); - routes.MapRoute( name: "default", template: "{controller:slugify=Home}/{action:slugify=Index}/{id?}"); diff --git a/src/Web/Views/Shared/_LoginPartial.cshtml b/src/Web/Views/Shared/_LoginPartial.cshtml index 1f454f6..5adb1af 100644 --- a/src/Web/Views/Shared/_LoginPartial.cshtml +++ b/src/Web/Views/Shared/_LoginPartial.cshtml @@ -2,7 +2,7 @@ {
-