Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Apr 01, 2021 @ 15:26
    Huw Reddick
    0

    MemberAuthorize attribute throws 500 error in Views not a 403 error

    Is there any reason that it throws a HttpException with a 500 status rather than a 403 error?

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Apr 01, 2021 @ 15:47
    Huw Reddick
    1

    mmm, seems it does return a 403, however if it is a Html.RenderAction in a view the view errors with a 500 error :(

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Apr 01, 2021 @ 16:28
    Huw Reddick
    0

    If anyone else needs this to work , I copied the Umbraco MemberAuthorizeAttribute code to create a CustomMemberAuthorizeAttribute and changed the HandleUnauthorizedRequest to set the filterContext rather than throw an exception

    protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
    {
        filterContext.Result = new HttpStatusCodeResult(403);
        //throw new HttpException(403, "Resource restricted: either member is not logged on or is not of a permitted type or group.");
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft