Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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. }