Beispiel #1
0
        public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }

            if (routeKey == null)
            {
                throw new ArgumentNullException(nameof(routeKey));
            }

            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            if (values.TryGetValue(routeKey, out object routeValue))
            {
                var parameterValueString = Convert.ToString(routeValue, CultureInfo.InvariantCulture);

                ContentResolverResults results = _resolver.ResolveRelativeUrlPathAsync(parameterValueString).Result;

                return(results != null && results.Found);
            }

            return(false);
        }
Beispiel #2
0
        public async Task <ActionResult> Index(string urlPath)
        {
            ContentResolverResults results;

            try
            {
                results = await _contentResolver.ResolveRelativeUrlPathAsync(urlPath);
            }
            catch (Exception ex)
            {
                return(new ContentResult
                {
                    Content = $"There was an error while resolving the URL. Check if your URL was correct and try again. Details: {ex.Message}",
                    StatusCode = 500
                });
            }

            if (results != null)
            {
                if (results.Found)
                {
                    if (results.ContentItemCodenames != null && results.ContentItemCodenames.Any())
                    {
                        return(await RenderViewAsync(results.ContentItemCodenames, results.ViewName));
                    }
                    else if (!string.IsNullOrEmpty(results.RedirectUrl))
                    {
                        return(LocalRedirectPermanent($"/{results.RedirectUrl}"));
                    }
                }
                else if (!string.IsNullOrEmpty(results.RedirectUrl))
                {
                    return(RedirectPermanent(results.RedirectUrl));
                }
            }

            return(NotFound());
        }