Copied to clipboard

Flag this post as spam?

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


  • Ben Palmer 180 posts 866 karma points c-trib
    Apr 10, 2019 @ 15:09
    Ben Palmer
    0

    Changing the Error when using MemberAuthorize

    Hi,

    I have an Umbraco 7 site that makes heavy use of custom API endpoints, some of these are protected to only allow members through.

    I've hit a slight problem when this happens as we display the error that gets returned, Authorization denied for this request.

    Obviously this isn't very user-friendly so I was wondering if there is a way to change or server a different message. For example, if the member hits the endpoint while logged out, it returns a more friendly message of You have been logged out, please log back in and try again, or similar.

    An example of how my method is set up:

    [HttpPost]
    [AcceptVerbs("POST")]
    [Umbraco.Web.WebApi.MemberAuthorize(AllowType = "member")]
    public HttpResponseMessage Add(AddCommentSubmission submission) {}
    

    If this isn't possible using the middleware, my next option would be to catch the forbidden request in JavaScript but I'd like to keep all errors returning as-is from the api.

    Thanks,

    Ben

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies