public IEnumerable <UmbracoEntityReference> GetReferences(object value) { List <UmbracoEntityReference> references = new List <UmbracoEntityReference>(); if (value is not string json) { return(references); } IRedirectDestination destination = OutboundRedirect.Deserialize(json)?.Destination; if (destination == null) { return(references); } switch (destination.Type) { case RedirectDestinationType.Media: references.Add(new UmbracoEntityReference(new GuidUdi("media", destination.Key))); break; case RedirectDestinationType.Content: references.Add(new UmbracoEntityReference(new GuidUdi("content", destination.Key))); break; } return(references); }
/// <summary> /// Gets an instance of <see cref="OutboundRedirect"/> representing the outbound redirect from the property /// with specified alias <paramref name="propertyAlias"/>. /// /// This method will ensure that you'll always get an instance of <see cref="OutboundRedirect"/> even though /// the property may not hold a redirect. You can then use the <see cref="OutboundRedirect.IsValid"/> property /// to check that the redirect is in fact valid. /// </summary> /// <param name="content">The content item holding the property.</param> /// <param name="propertyAlias">The alias of the property.</param> /// <returns>An instance of <see cref="OutboundRedirect"/>.</returns> public static OutboundRedirect GetOutboundRedirect(this IPublishedContent content, string propertyAlias) { if (String.IsNullOrWhiteSpace(propertyAlias)) { throw new ArgumentNullException(nameof(propertyAlias)); } OutboundRedirect redirect = content.GetPropertyValue(propertyAlias) as OutboundRedirect; return(redirect ?? new OutboundRedirect()); }
/// <summary> /// Virtual method for handling outbound redirects - wich is redirects pointing from content in Umbraco to somewhere else. /// </summary> /// <param name="request">The current request.</param> protected virtual void HandleOutboundRedirects(SpaRequest request) { // Get the outbound URL from the current page (if set) OutboundRedirect redirect = request.Content?.GetOutboundRedirect(); // If the redirect is valid, we'll set the response to return a redirect if (redirect != null && redirect.HasDestination) { request.Response = ReturnRedirect(request, redirect.Destination.Url, redirect.IsPermanent); } }
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview) { return(OutboundRedirect.Deserialize(source as string)); }
/// <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> /// <param name="redirectsService">A reference to the current redirects service.</param> /// <returns>The destination URL.</returns> public static string GetDestinationUrl(this OutboundRedirect redirect, Uri uri, IRedirectsService redirectsService) { return(redirectsService.GetDestinationUrl(redirect, uri)); }