Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
Role base authentication with custom error with role name in dot net 6

I use the below the line for role based authentication at top of methods in controllers

[HttpGet("getAll"), Authorize(Roles = "GetAll")]

When a user doesn't have access to this role, I want to tell the user that you need the role "GetAll"

Is it possible?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can check the role in the method, something like this:

[HttpGet("getAll"), Authorize]
        public async Task<IActionResult> GetAll()
        {
            if (!Roles.Any(r => r == "getAll"))
            {
                return Unauthorized("Pass the role name");
            }

            return Ok();
        }

Roles contains the roles that user access

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda