Text version of the video
https://csharp-video-tutorials.blogsp...
Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Text Articles & Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Tutorial
https://www.youtube.com/playlist?list...
Angular, JavaScript, jQuery, Dot Net & SQL Playlists
https://www.youtube.com/user/kudvenka...
If the logged-in user is in Admin role, then we want to display Manage Roles navigation menu item. If the logged-in user IS NOT in Admin role, then Manage Roles navigation menu item should not be displayed.
Show or hide navigation menu based on logged-in user role
Navigation menu is in the laylout view (_Layout.cshtml).
Inject SignInManager service into the layout view using @inject directive
Use the SignInManager service, IsSignedIn() method and IsInRole() method to check if the user is signed in and if the user is in the Admin role
@using Microsoft.AspNetCore.Identity
@inject SignInManager[ApplicationUser] SignInManager
[ul class="navbar-nav"] [li class="nav-item"] [a class="nav-link" asp-controller="home" asp-action="index"]List[/a] [/li] [li class="nav-item"] [a class="nav-link" asp-controller="home" asp-action="create"]Create[/a] [/li] @if (SignInManager.IsSignedIn(User) && User.IsInRole("Admin")) { [li class="nav-item"] [a class="nav-link" asp-controller="Administration" asp-action="ListRoles"] Manage Roles [/a] [/li] }
[/ul]
What if the user types the URL in address bar
The URL associated with Manage Roles navigation menu item is /Administration/ListRoles. What if the user types this URL directly in the address bar.
The Authorize attribute on the AdministrationController protects from the unauthorised access. If the logged-in user is not in Admin role, asp.net core automatically redirects the user to /Account/AccessDenied.
[Authorize(Roles = "Admin")]
public class AdministrationController : Controller
{ // Code
}
AccessDenied action in AccountController
public class AccountController : Controller
{ [HttpGet] [AllowAnonymous] public IActionResult AccessDenied() { return View(); } // Other actions
}
AccessDenied View
[div class="text-center"] [h1 class="text-danger"]Access Denied[/h1] [h6 class="text-danger"]You do not have persmission to view this resource[/h6] [img src="~/images/noaccess.png" style="height:300px; width:300px" /]
[/div]
asp.net core docker Show or hide navigation menu based on user role in asp net core | |
108 Likes | 108 Dislikes |
6,640 views views | 524K followers |
Science & Technology | Upload TimePublished on 25 Jul 2019 |
Related keywords
tutorialspoint,ajax meaning,tutorials dojo,central park 5,asp.net core github,craigslist nj,asp.net core 3,server status,ajax fc,ajax players,server jobs nyc,asp.net core swagger,credit karma,tutorials by hugo,mvc design pattern,server error in '/' application,servers for minecraft,asp.net core dependency injection,asp.net core 3.0,tutorialspoint c#,calculator,tutorialspoint tableau,ajax ontario,asp.net core 3 release date,server job description,tutorials by a,mvc hours,tutorialspoint python,asp.net core web api,ajax jquery,craigslist ny,ajax call,server pro,server status ffxiv,cheap flights,server memes,asp.net core hosting,chase,tutorialspoint java,serverless architecture,tutorialspoint java compiler,server resume,server books,tutorialspoint javascript,mvcc connect,college football,ajax deadpool,server jobs,cvs,cnn,mvc tutorial,costco hours,tutorialspoint sql,server side rendering,tutorialspoint spring,serverless,tutorialspoint spark,mvc nj,asp.net core download,cool math games,citibank,asp.net core identity,ajax parking,asp.net core logging,tutorialsystems,mvconnect,cunyfirst,ajax post,ajax jersey,asp.net core razor pages,server duties,asp.net core environment variables,tutorials near me,server 2019,chernobyl,century 21,serverminer,ajax cleaner,mvcsd,mvcsc,asp.net core configuration,ajax marvel,mvc medical,asp.net core tutorial,ajax roster,mvc architecture,mvc2,asp.net core mvc,ajax soccer,chase online,server hosting,costco,server jobs near me,ajax dish soap,capital one,server rack,tutorialspoint html,craigslist,ajax tavern,tutorialsteacher,ajax javascript,tutorialspoint reactjs,ajax request,asp.net core 2.2,tutorialspoint python 3,asp.net core signalr,mvc framework,ajax paving,mvc near me,ajax greek,mvc pattern,mvcu,tutorialspoint spring boot,asp.net core middleware,mvc map,mvc webadvisor,mvcc,mvci,mvctc,
No comments:
Post a Comment