Getting Started With ASP.NET Core 2.0 Identity And Role Management

In this article, we will see in detail how to use ASP.NET Core Identity in MVC Application for creating user roles and displaying the menu depending on user roles.

C# (2.1 MB)
 
 
 
 
 
5 Star
(1)
1,259 times
Add to favorites
3/22/2018
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
@model ExternalLoginsViewModel
@{
    ViewData["Title"] = "Manage your external logins";
    ViewData.AddActivePage(ManageNavPages.ExternalLogins);
}

@Html.Partial("_StatusMessage", Model.StatusMessage)
@if (Model.CurrentLogins?.Count > 0)
{
    <h4>Registered Logins</h4>
    <table class="table">
        <tbody>
            @foreach (var login in Model.CurrentLogins)
            {
                <tr>
                    <td>@login.LoginProvider</td>
                    <td>
                        @if (Model.ShowRemoveButton)
                        {
                            <form asp-action="RemoveLogin" method="post">
                                <div>
                                    <input asp-for="@login.LoginProvider" name="LoginProvider" type="hidden" />
                                    <input asp-for="@login.ProviderKey" name="ProviderKey" type="hidden" />
                                    <button type="submit" class="btn btn-default" title="Remove this @login.LoginProvider login from your account">Remove</button>
                                </div>
                            </form>
                        }
                        else
                        {
                            @: &nbsp;
                        }
                    </td>
                </tr>
            }
        </tbody>
    </table>
}
@if (Model.OtherLogins?.Count > 0)
{
    <h4>Add another service to log in.</h4>
    <hr />
    <form asp-action="LinkLogin" method="post" class="form-horizontal">
        <div id="socialLoginList">
            <p>
                @foreach (var provider in Model.OtherLogins)
                {
                    <button type="submit" class="btn btn-default" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
                }
            </p>
        </div>
    </form>
}