示例#1
0
    public IActionResult GetClientError(ActionContext actionContext, IClientErrorActionResult clientError)
    {
        if (clientError is null)
        {
            throw new System.ArgumentNullException(nameof(clientError));
        }

        if (clientError.StatusCode.HasValue)
        {
            switch (clientError.StatusCode.Value)
            {
            case StatusCodes.Status400BadRequest:
                return(ErrorResult.BadRequest().ToActionResult());

            case StatusCodes.Status401Unauthorized:
                return(ErrorResult.Unauthorized().ToActionResult());

            case StatusCodes.Status403Forbidden:
                return(ErrorResult.Forbidden().ToActionResult());

            case StatusCodes.Status404NotFound:
                return(ErrorResult.NotFound("Not Found").ToActionResult());

            case StatusCodes.Status409Conflict:
                return(ErrorResult.Conflict("Conflict").ToActionResult());

            case StatusCodes.Status500InternalServerError:
                return(ErrorResult.ServerError().ToActionResult());
            }
        }

        return(ErrorResult.Unknown(clientError.StatusCode).ToActionResult());
    }
示例#2
0
        public override async Task <PipelineContinuation> Operate(PipelineContext context)
        {
            var authenticationMethod = context.Items["__AuthenticationMethod"] as IAuthenticationMechanism;

            if (authenticationMethod != null)
            {
                context.Result = await authenticationMethod.AuthenticateAndAuthorize(context, this.Attribute);

                if (context.Result != null)
                {
                    return(PipelineContinuation.SkipToPostHandler);
                }

                return(PipelineContinuation.Continue);
            }

            // Here we require auth, but really can't work out how to serve the user, so give default response
            context.Result = ErrorResult.Unauthorized();
            return(PipelineContinuation.SkipToPostHandler);
        }