/// <summary> /// Returns the calculated destination URL for the specified <paramref name="redirect"/>. /// </summary> /// <param name="redirect">The redirect.</param> /// <param name="uri">The inbound URL.</param> /// <returns>The destination URL.</returns> public virtual string GetDestinationUrl(IRedirectBase redirect, Uri uri) { if (string.IsNullOrWhiteSpace(redirect?.Destination?.Url)) { return(null); } // Get the query string (if any) string query = redirect.Destination.Query; // Get the fragment (if any) string fragment = redirect.Destination.Fragment; // Merge the existing query string with the query string of "uri" (eg. from the inbound request) if (uri != null && uri.Query.HasValue() && redirect.ForwardQueryString) { query = MergeQueryString(query, uri.Query); } // For content and media, we need to look up the most recent URL IPublishedContent content = null; switch (redirect.Destination.Type) { case RedirectDestinationType.Content: if (_umbracoContextAccessor.TryGetUmbracoContext(out IUmbracoContext context)) { content = context.Content.GetById(redirect.Destination.Key); } break; case RedirectDestinationType.Media: if (_umbracoContextAccessor.TryGetUmbracoContext(out context)) { content = context.Media.GetById(redirect.Destination.Key); } break; } // Put the destination URL back together return(RedirectsUtils.ConcatUrl(content?.Url() ?? redirect.Destination.Url, query, fragment)); }
/// <summary> /// Returns the calculated destination URL for the specified <paramref name="redirect"/>. /// </summary> /// <param name="redirect">The redirect.</param> /// <returns>The destination URL.</returns> public virtual string GetDestinationUrl(IRedirectBase redirect) { return(GetDestinationUrl(redirect, null)); }