Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AuthorizeAttribute.cs 591B

1234567891011121314151617
  1. namespace Diligent.WebAPI.Host.Attributes
  2. {
  3. [ExcludeFromCodeCoverage]
  4. [AttributeUsage(AttributeTargets.Method)]
  5. public class AuthorizeAttribute : Attribute, IAuthorizationFilter
  6. {
  7. public void OnAuthorization(AuthorizationFilterContext context)
  8. {
  9. User? user = (User?)context.HttpContext.Items["User"];
  10. if (user == null)
  11. {
  12. // not logged in
  13. context.Result = new JsonResult(new { message = "Unauthorized" }) { StatusCode = StatusCodes.Status401Unauthorized };
  14. }
  15. }
  16. }
  17. }