UrlAbsolute and UrlWIthDomain not supported for PublishedItemType.Media ?
Hi. Trying to get url with domain for reverse proxy reasons. I need to get all my media, content urls etc to return the current domains.
I am trying to use use UrlWithDomain() which I see just returns UrlAbsolute() in the source. However this is the method:
public static string UrlAbsolute(this IPublishedContent content)
{
switch (content.ItemType)
{
case PublishedItemType.Content:
if (UmbracoContext.Current == null)
throw new InvalidOperationException("Cannot resolve a Url for a content item when UmbracoContext.Current is null.");
if (UmbracoContext.Current.UrlProvider == null)
throw new InvalidOperationException("Cannot resolve a Url for a content item when UmbracoContext.Current.UrlProvider is null.");
return UmbracoContext.Current.UrlProvider.GetUrl(content.Id, true);
case PublishedItemType.Media:
throw new NotSupportedException("AbsoluteUrl is not supported for media types.");
default:
throw new ArgumentOutOfRangeException();
}
}
So the question is... if media is not supported using UrlAbsolute() is there a alternate static that is without writing our own extension?
if anyone else runs into this issue I just ended up writing a custom string extension that essentially got me what I needed.
public static class StringExtensions
{
/// <summary>Gets the absolute url for the media.</summary>
/// <param name="UrlPath">The content.</param>
/// <returns>The absolute url for the media.</returns>
public static string WithDomain(this string UrlPath)
{
Uri domain = HttpContext.Current.Request.Url;
if (UrlPath.IndexOf('/') != 0)
UrlPath = "/" + UrlPath;
return domain.GetLeftPart(UriPartial.Authority) + UrlPath;
}
}
UrlAbsolute and UrlWIthDomain not supported for PublishedItemType.Media ?
Hi. Trying to get url with domain for reverse proxy reasons. I need to get all my media, content urls etc to return the current domains. I am trying to use use UrlWithDomain() which I see just returns UrlAbsolute() in the source. However this is the method:
So the question is... if media is not supported using UrlAbsolute() is there a alternate static that is without writing our own extension?
if anyone else runs into this issue I just ended up writing a custom string extension that essentially got me what I needed.
is working on a reply...