Create logout for ASP.Net Web App

From TRCCompSci - AQA Computer Science
Revision as of 13:54, 16 October 2024 by Admin (talk | contribs) (Created page with "Create a new Razor Page called `logout`. Go to the logoutModel code section (right click it in solution explorer and select goto PageModel). Now change the `OnGet` method to...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Create a new Razor Page called `logout`.

Go to the logoutModel code section (right click it in solution explorer and select goto PageModel).

Now change the `OnGet` method to this:

<syntaxhighlight lang=c#>

       public IActionResult OnGet()
       {

HttpContext.Session.Clear();

return LocalRedirect("/Index"); } <syntaxhighlight>