Exemplo n.º 1
0
        public IActionResult TryHandle(IRequestHandler requestHandler, string url)
        {
            IEndpointResolver endpointResolver = requestHandler.HttpContext.RequestServices.GetService <IEndpointResolver>();
            Endpoint          endpoint         = endpointResolver.GetEndpoint(requestHandler, url);

            if (endpoint == null)
            {
                return(null);
            }

            if (endpoint.DisallowAnonymous)
            {
                if (!requestHandler.HttpContext.User.Identity.IsAuthenticated || !this.HasRequiredClaims(requestHandler, endpoint))
                {
                    if (string.IsNullOrEmpty(endpoint.SignInUrl))
                    {
                        throw new HttpException(403, "Access denied.");
                    }

                    return((requestHandler as Controller).Redirect(endpoint.SignInUrl));
                }
            }

            IEndpoint endpointInstance = this.GetEndpointInstance(endpoint);

            if (endpointInstance == null)
            {
                return(null);
            }

            return(endpointInstance.Invoke(requestHandler, endpoint, endpointResolver.GetParameters(endpoint.UrlTemplate, url)));
        }