Answer the question
In order to leave comments, you need to log in
What do I need to put in the role-based authorization code in ASP.NET Core?
Hello, I am doing a project and I need to make sure that only read-only mode is available to non-authenticated users (search is available, company creation is not available, comments, likes and ratings are not available) and Authenticated users have access to everything except the admin panel. I want to do this with role-based authorization in ASP.NET Core - https://docs.microsoft.com/en-us/aspnet/core/secur... . But I don't know what to write inside.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyWebSite.Models
{
[Authorize(Roles = "User")]
public class UserController : Controller
{
// что здесь писать?
}
}
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyWebSite.Models
{
[Authorize(Roles = "Administrator")]
public class AdministratorController : Controller
{
// что здесь писать?
}
}
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace MyWebSite.Models
{
[Authorize]
public class VisitorsController : Controller
{
public ActionResult SetTime()
{
// что здесь писать?
}
[AllowAnonymous]
public ActionResult Login()
{
// что здесь писать?
}
}
}
Answer the question
In order to leave comments, you need to log in
write your own business logic. You have already "explained" to aspnet that only users with a specific role can access these methods.
Hoch.
https://docs.microsoft.com/ru-ru/aspnet/web-api/ov...
https://identityserver4.readthedocs.io/en/latest/
However, I recommend using AZURE AD, it's fast and not very stressful
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question