Authorization works with roles properly. Added authorization examples to Sample project.
This commit is contained in:
@@ -6,14 +6,19 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sample.Models;
|
||||
using Raven.Client;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Sample.Controllers
|
||||
{
|
||||
public class HomeController : RavenController
|
||||
{
|
||||
public HomeController(IAsyncDocumentSession dbSession)
|
||||
private UserManager<AppUser> userManager;
|
||||
|
||||
public HomeController(IAsyncDocumentSession dbSession, UserManager<AppUser> userManager)
|
||||
: base(dbSession)
|
||||
{
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Index()
|
||||
@@ -27,6 +32,20 @@ namespace Sample.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
// Require that the user be logged in.
|
||||
[Authorize]
|
||||
public IActionResult Auth()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
// Require that the user be in the Admin role.
|
||||
[Authorize(Roles = "Admin")]
|
||||
public IActionResult AuthAdmin()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult About()
|
||||
{
|
||||
ViewData["Message"] = "Your application description page.";
|
||||
|
||||
Reference in New Issue
Block a user