Skip to content

Commit 2fe5a19

Browse files
authored
Merge pull request #28 from KAJOOSH/master
Upgrade to .NET 6
2 parents 16cf6f6 + 0666219 commit 2fe5a19

File tree

70 files changed

+41266
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+41266
-67
lines changed

DynamicRoleBasedAuthorization.sln

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29613.14
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.32014.148
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamicAuthorization.Mvc.Core", "src\DynamicAuthorization.Mvc.Core\DynamicAuthorization.Mvc.Core.csproj", "{89E57FDC-5AF7-4AAF-A40B-FBA91D41ECF4}"
77
EndProject
@@ -33,6 +33,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "netcore2.1", "netcore2.1",
3333
EndProject
3434
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleMvc2WebApp", "samples\netcore2.1\SampleMvc2WebApp\SampleMvc2WebApp.csproj", "{BB7818FD-9200-4FD7-83F7-90EB0034D2F9}"
3535
EndProject
36+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net6", "net6", "{316BAD5C-847E-4BD5-AA4C-E272DD109D31}"
37+
EndProject
38+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleMvcWebWithUi", "samples\net6\SampleMvcWebWithUi\SampleMvcWebWithUi.csproj", "{09B590EC-D887-4517-A386-EBE88D3DB591}"
39+
EndProject
3640
Global
3741
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3842
Debug|Any CPU = Debug|Any CPU
@@ -75,6 +79,10 @@ Global
7579
{BB7818FD-9200-4FD7-83F7-90EB0034D2F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
7680
{BB7818FD-9200-4FD7-83F7-90EB0034D2F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
7781
{BB7818FD-9200-4FD7-83F7-90EB0034D2F9}.Release|Any CPU.Build.0 = Release|Any CPU
82+
{09B590EC-D887-4517-A386-EBE88D3DB591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
83+
{09B590EC-D887-4517-A386-EBE88D3DB591}.Debug|Any CPU.Build.0 = Debug|Any CPU
84+
{09B590EC-D887-4517-A386-EBE88D3DB591}.Release|Any CPU.ActiveCfg = Release|Any CPU
85+
{09B590EC-D887-4517-A386-EBE88D3DB591}.Release|Any CPU.Build.0 = Release|Any CPU
7886
EndGlobalSection
7987
GlobalSection(SolutionProperties) = preSolution
8088
HideSolutionNode = FALSE
@@ -92,6 +100,8 @@ Global
92100
{2CAEFC83-24BF-4C92-B6F1-B3C6714220F2} = {A7EEBB7E-C64D-4475-93D0-872E080A4E03}
93101
{42149EE2-E873-4CBB-BAC0-791132031F46} = {BAAF9837-1DB5-4032-AB2A-2901E6EE6EF8}
94102
{BB7818FD-9200-4FD7-83F7-90EB0034D2F9} = {42149EE2-E873-4CBB-BAC0-791132031F46}
103+
{316BAD5C-847E-4BD5-AA4C-E272DD109D31} = {BAAF9837-1DB5-4032-AB2A-2901E6EE6EF8}
104+
{09B590EC-D887-4517-A386-EBE88D3DB591} = {316BAD5C-847E-4BD5-AA4C-E272DD109D31}
95105
EndGlobalSection
96106
GlobalSection(ExtensibilityGlobals) = postSolution
97107
SolutionGuid = {18C80710-C9E9-488B-9100-1E4BF8B18038}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Dynamic Role-Based Authorization in ASP.NET Core MVC 2.1, 3.1 and 5.0 [![NuGet](http://img.shields.io/nuget/v/DynamicAuthorization.Mvc.Core.svg?style=flat)](https://www.nuget.org/packages/DynamicAuthorization.Mvc.Core)
1+
# Dynamic Role-Based Authorization in ASP.NET Core MVC 2.1, 3.1, 5.0 and 6.0 [![NuGet](http://img.shields.io/nuget/v/DynamicAuthorization.Mvc.Core.svg?style=flat)](https://www.nuget.org/packages/DynamicAuthorization.Mvc.Core)
22

33
You already know how role-based authorization works in ASP.NET Core.
44

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "/Views/Shared/_Layout.cshtml";
3+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.AspNetCore.Identity;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Logging;
4+
using SampleMvcWebWithUi.Models;
5+
using System.Diagnostics;
6+
using System.Threading.Tasks;
7+
8+
namespace SampleMvcWebWithUi.Controllers
9+
{
10+
public class HomeController : Controller
11+
{
12+
private readonly ILogger<HomeController> _logger;
13+
private readonly RoleManager<ApplicationRole> _roleManager;
14+
15+
public HomeController(ILogger<HomeController> logger, RoleManager<ApplicationRole> roleManager)
16+
{
17+
_logger = logger;
18+
_roleManager = roleManager;
19+
}
20+
21+
public async Task<IActionResult> Index()
22+
{
23+
//var role = new ApplicationRole { Name = "Test1" };
24+
//var result = await _roleManager.CreateAsync(role);
25+
26+
return View();
27+
}
28+
29+
public IActionResult Privacy()
30+
{
31+
return View();
32+
}
33+
34+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
35+
public IActionResult Error()
36+
{
37+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
38+
}
39+
}
40+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore;
3+
using SampleMvcWebWithUi.Models;
4+
5+
namespace SampleMvcWebWithUi.Data
6+
{
7+
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int,
8+
ApplicationUserClaim, ApplicationUserRole, ApplicationUserLogin, ApplicationRoleClaim, ApplicationUserToken>
9+
{
10+
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
11+
: base(options)
12+
{
13+
}
14+
15+
protected override void OnModelCreating(ModelBuilder modelBuilder)
16+
{
17+
base.OnModelCreating(modelBuilder);
18+
19+
modelBuilder.Entity<ApplicationUser>(b =>
20+
{
21+
// Each User can have many UserClaims
22+
b.HasMany(e => e.Claims)
23+
.WithOne(e => e.User)
24+
.HasForeignKey(uc => uc.UserId)
25+
.IsRequired();
26+
27+
// Each User can have many UserLogins
28+
b.HasMany(e => e.Logins)
29+
.WithOne(e => e.User)
30+
.HasForeignKey(ul => ul.UserId)
31+
.IsRequired();
32+
33+
// Each User can have many UserTokens
34+
b.HasMany(e => e.Tokens)
35+
.WithOne(e => e.User)
36+
.HasForeignKey(ut => ut.UserId)
37+
.IsRequired();
38+
39+
// Each User can have many entries in the UserRole join table
40+
b.HasMany(e => e.UserRoles)
41+
.WithOne(e => e.User)
42+
.HasForeignKey(ur => ur.UserId)
43+
.IsRequired();
44+
});
45+
46+
modelBuilder.Entity<ApplicationRole>(b =>
47+
{
48+
// Each Role can have many entries in the UserRole join table
49+
b.HasMany(e => e.UserRoles)
50+
.WithOne(e => e.Role)
51+
.HasForeignKey(ur => ur.RoleId)
52+
.IsRequired();
53+
54+
// Each Role can have many associated RoleClaims
55+
b.HasMany(e => e.RoleClaims)
56+
.WithOne(e => e.Role)
57+
.HasForeignKey(rc => rc.RoleId)
58+
.IsRequired();
59+
});
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)