YetkiController.cs sayfası aşağıdaki gibi olacaktır.
Yetkilerle ilgili işlemler bittiğinde aşağıda yorum satırı olan
[Authorize(Roles =”Yetkiler”)] ifadesini açarak bu sayfaya sadece Yetkiler yetkisine sahip kullanıcıların erişmesini sağlayacaktır.
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
//using YesilayKlubu.Models;
namespace YesilayKlubu.Controllers
{
// [Authorize(Roles ="Yetkiler")]
public class YetkiController : Controller
{
private UserManager<AppUser> userManager;
private RoleManager<IdentityRole> roleManager;
public YetkiController(
UserManager<AppUser> _userManager,
RoleManager<IdentityRole> _roleManager
)
{
userManager = _userManager;
roleManager = _roleManager;
}
public IActionResult Index()
{
var yetkiler = roleManager.Roles.ToList();
return View(yetkiler);
}
}
}
Views\Yetki\Index.cshtml
@using Microsoft.AspNetCore.Identity
@model List<IdentityRole>
@{
ViewData["Title"] = "Index";
}
<div class="row">
<div class="col-10">
<h1>Yetkiler</h1></div>
<div class="col-2">
<a class="btn btn-primary" asp-action="Yeni">Yeni Yetki</a>
</div>
</div>
<table class="table">
<thead>
<tr>
<th>Yetki</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@item.Name</td>
<td><a asp-action="Sil" asp-route-id="@item.Id" class="btn btn-danger sil">
<i class="bi bi-trash3"></i>
Sil</a>
</td>
<td><a asp-action="Duzenle" asp-route-id="@item.Id">Düzenle</a></td>
<td><a asp-action="YetkiliKullanicilar" asp-route-id="@item.Id">Yetkili Kullanıcılar</a></td>
</tr>
}
</tbody>
</table>
@section Scripts{
<script>
$(document).ready(function () {
$(".sil").click(function () {
return confirm("Silmek istediğinizden emin misiniz?");
});
})
</script>
}
