Copied to clipboard

Flag this post as spam?

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


  • Biagio Paruolo 1594 posts 1825 karma points c-trib
    Dec 09, 2022 @ 11:40
    Biagio Paruolo
    0

    Using UmbracoMemberAuthorize in custom API controller: How to return only 401 code and not the error page?

    Using UmbracoMemberAuthorize in custom API controller: How to return only 401 code and not the error page?

    I've this code:

                [UmbracoMemberAuthorize("", "Socio", "")]
        [ActionName("Content")]
        [HttpGet]
        public async Task<IActionResult> Content(Guid id)
        {
            var content = _contentService.GetById(id);
    
            var flag = await IsAuthorizedToSeeData(id);
    
            if (flag)
            {
                return Ok(ContentFor(id));
            }
            else
                return Unauthorized();
    
        }
    

    I wish to return 401 and not go to the login/error page.

  • Sean Valentine 11 posts 100 karma points
    Dec 17, 2022 @ 17:27
    Sean Valentine
    0

    Bumping this as i could really do with knowing how to solve this issue as well.

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Dec 18, 2022 @ 06:41
    Huw Reddick
    0

    Not exactly sure what you are attempting to do, so perhaps you could explain a little more.

    The UmbracoMemberAuthorize attribute checks if your logged in member has access to the action being called and is idependant of the actual code in your action, maybe you should be using a custom authorise attribute for what you require.

Please Sign in or register to post replies

Write your reply to:

Draft