Difference between revisions of "Create logout for ASP.Net Web App"
Line 13: | Line 13: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | Changing the `void` to `IActionResult` means this returns a page. The code will clear the current session which essentially will logout the user. Finally it redirects back to the index page. |
Latest revision as of 13:56, 16 October 2024
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:
public IActionResult OnGet()
{
HttpContext.Session.Clear();
return LocalRedirect("/Index");
}
Changing the `void` to `IActionResult` means this returns a page. The code will clear the current session which essentially will logout the user. Finally it redirects back to the index page.