ASP.NET Core: Razor Pages

SignOut Authentication Pages

Adding a Signed In Message

In the template file Pages/Shared/_Layout.cshtml add some conditional logic to display a logout message to logged in users. Note the use of User.Identity.IsAuthenticated.

PAGE: Pages/Shared/_Layout.cshtml

Building a Sign Out

Once logged in a cookie has been created to control authentication.

The Cookie named .AspNetCore.Identity.Application could be deleted to simulate a logout, however we'll add that functionality to our pages.

Tip: The Cookie controlling the Identity framework can be renamed in Startup.cs in the options for the ConfigureApplicationCookie using an option value of Cookie.Name

In the pages/Secure folder, create a page called SignOut.cshtml. Do so via:

This will create a .cshtml page and an associated .cshtml.cs page model file.

Edit the Page Model Pages/Secure/SignOut.cshtml.cs

PAGE MODEL: Pages/Secure/SignOut.cshtml.cs

Next edit the Page Pages/Secure/SignIn.cshtml. Notice how this is just left blank but we need to produce it because of Razor page architecture.

PAGE: Pages/Secure/SignIn.cshtml