Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AuthorizeAttribute.cs 561B

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