Skip to content

Commit 954ad8c

Browse files
roles in asp.net core
1 parent af0ed19 commit 954ad8c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Webgentle.BookStore/Webgentle.BookStore/Controllers/HomeController.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
23
using Microsoft.Extensions.Configuration;
34
using Microsoft.Extensions.Options;
45
using System;
@@ -69,6 +70,8 @@ public ViewResult AboutUs()
6970
return View();
7071
}
7172

73+
// Uncomment the below line to enable roles on this action method.
74+
//[Authorize(Roles ="Admin,User")]
7275
public ViewResult ContactUs()
7376
{
7477
return View();

Webgentle.BookStore/Webgentle.BookStore/Repository/AccountRepository.cs

+3
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@ public class AccountRepository : IAccountRepository
1313
{
1414
private readonly UserManager<ApplicationUser> _userManager;
1515
private readonly SignInManager<ApplicationUser> _signInManager;
16+
private readonly RoleManager<IdentityRole> _roleManager;
1617
private readonly IUserService _userService;
1718
private readonly IEmailService _emailService;
1819
private readonly IConfiguration _configuration;
1920

2021
public AccountRepository(UserManager<ApplicationUser> userManager,
2122
SignInManager<ApplicationUser> signInManager,
23+
RoleManager<IdentityRole> roleManager,
2224
IUserService userService,
2325
IEmailService emailService,
2426
IConfiguration configuration)
2527
{
2628
_userManager = userManager;
2729
_signInManager = signInManager;
30+
_roleManager = roleManager;
2831
_userService = userService;
2932
_emailService = emailService;
3033
_configuration = configuration;

0 commit comments

Comments
 (0)