PageFilter and on page authorization check example - PuzzleServer/mainpuzzleserver GitHub Wiki
public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
AuthorizationResult authResult;
switch (this.EventRole)
{
case (EventRole.admin):
authResult = authorizationService.AuthorizeAsync(User, "IsEventAdmin").Result;
break;
case (EventRole.author):
authResult = authorizationService.AuthorizeAsync(User, "IsEventAuthor").Result;
break;
case (EventRole.play):
default:
authResult = authorizationService.AuthorizeAsync(User, "IsEventPlayer").Result;
break;
}
if (authResult.Succeeded)
{
await base.OnPageHandlerExecutionAsync(context, next);
}
else if (User.Identity.IsAuthenticated)
{
context.Result = new ForbidResult();
}
else
{
context.Result = new ChallengeResult();
}
}