Mischa Morf
Mischa Morf

Reputation: 331

asp.net core 2 authorization Logout MVC

I currently authenticate my starting View of my MVC Application by adding the following Code to my Controller and it works great.

    [Authorize(Roles = "Domain Users")]

Im wondering if there is also something that allows you to log out of that authorization again. Havent found anything regarding it so far, anyone worked with it before?

Upvotes: 0

Views: 838

Answers (1)

Jeremie de Vos
Jeremie de Vos

Reputation: 184

This is what i used in a asp.net core 2.2 project of mine.

@using Microsoft.AspNetCore.Identity
@using Website.DAL.Models.Users

@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager


           <form asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Action("Index", "Home", new { area = "" })" method="post" id="logoutForm" class="ml-auto">
                <ul class="nav navbar-top-links navbar-right">
                    <li><button type="submit" class="fa fa-sign-out btn btn-w-m btn-link">Logout</button></li>
                </ul>
            </form>

However it is logingout the entire user. As far i know there is now way to unsubsribe a user or something like that.

Upvotes: 1

Related Questions