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,346 times
Add to favorites
E-mail Twitter Digg Facebook

Solution explorer

@model LoginWith2faViewModel
    ViewData["Title"] = "Two-factor authentication";

<hr />
<p>Your login is protected with an authenticator app. Enter your authenticator code below.</p>
<div class="row">
    <div class="col-md-4">
        <form method="post" asp-route-returnUrl="@ViewData["ReturnUrl"]">
            <input asp-for="RememberMe" type="hidden" />
            <div asp-validation-summary="All" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="TwoFactorCode"></label>
                <input asp-for="TwoFactorCode" class="form-control" autocomplete="off" />
                <span asp-validation-for="TwoFactorCode" class="text-danger"></span>
            <div class="form-group">
                <div class="checkbox">
                    <label asp-for="RememberMachine">
                        <input asp-for="RememberMachine" />
                        @Html.DisplayNameFor(m => m.RememberMachine)
            <div class="form-group">
                <button type="submit" class="btn btn-default">Log in</button>
    Don't have access to your authenticator device? You can 
    <a asp-action="LoginWithRecoveryCode" asp-route-returnUrl="@ViewData["ReturnUrl"]">log in with a recovery code</a>.

@section Scripts {
    @await Html.PartialAsync("_ValidationScriptsPartial")