Sdl.Web.Tridion/Resolvers/Linking/DefaultLinkResolver.cs
/// <summary>
/// Resolves a link URI (TCM URI or site URL) to a normalized site URL.
/// </summary>
/// <param name="sourceUri">The source URI (TCM URI or site URL)</param>
/// <param name="resolveToBinary">Specifies whether a link to a Multimedia Component should be resolved directly to its Binary (<c>true</c>) or as a regular Component link.</param>
/// <param name="localization">The context Localization (optional, since the TCM URI already contains a Publication ID, but this allows resolving in a different context).</param>
/// <returns>The resolved URL.</returns>
Resolves a link URI (TCM URI or site URL) to a normalized site URL.
Resolves a link URI ( TCM URI or site URL ) to a normalized site URL .
public string ResolveLink(string sourceUri, bool resolveToBinary = false, ILocalization localization = null)
        {
            if (sourceUri == null)
            {
                return null;
            }
            string url;
            if (sourceUri.IsCmIdentifier())
            {
                Tridion.ContentManager.TcmUri tcmUri = new Tridion.ContentManager.TcmUri(sourceUri);
                url = ResolveLink(tcmUri, resolveToBinary, localization);
            }
            else
            {
                url = sourceUri;
            }
            if (url != null && url.EndsWith(Constants.DefaultExtension))
            {
                url = url.Substring(0, url.Length - Constants.DefaultExtension.Length);
                if (url.EndsWith("/" + Constants.DefaultExtensionLessPageName))
                {
                    url = url.Substring(0, url.Length - Constants.DefaultExtensionLessPageName.Length);
                }
            }
            return url;
        }
public string ResolveLink ( string sourceUri , bool resolveToBinary = false , ILocalization localization = null ) { if ( sourceUri == null ) { return null ; } string url ; if ( sourceUri . IsCmIdentifier ( ) ) { Tridion . ContentManager . TcmUri tcmUri = new Tridion . ContentManager . TcmUri ( sourceUri ) ; url = ResolveLink ( tcmUri , resolveToBinary , localization ) ; } else { url = sourceUri ; } if ( url != null && url . EndsWith ( Constants . DefaultExtension ) ) { url = url . Substring ( 0 , url . Length - Constants . DefaultExtension . Length ) ; if ( url . EndsWith ( " " + Constants . DefaultExtensionLessPageName ) ) { url = url . Substring ( 0 , url . Length - Constants . DefaultExtensionLessPageName . Length ) ; } } return url ; }
Resolves a link URI (TCM URI or site URL) to a normalized site URL.
Resolves a link URI ( TCM URI or site URL ) to a normalized site URL .
// Strip off default extension / page name
The resolved URL.
The resolved URL .
sourceUri
string
The source URI (TCM URI or site URL)
The source URI ( TCM URI or site URL )
resolveToBinary
bool
Specifies whether a link to a Multimedia Component should be resolved directly to its Binary (true
Specifies whether a link to a Multimedia Component should be resolved directly to its Binary ( true
localization
ILocalization
The context Localization (optional, since the TCM URI already contains a Publication ID, but this allows resolving in a different context).
The context Localization ( optional since the TCM URI already contains a Publication ID but this allows resolving in a different context ) .