18

Getting the URL of a MediaItem is pretty straightforward, you pass the MediaItem reference to Sitecore.Resources.Media.MediaManager.GetMediaUrl: var url = MediaManager.GetMediaUrl(mediaItem); GetMediaUrl takes an optional second parameter of Sitecore.Resources.Media.MediaUrlOptions, which can be used to add query string parameters to the URL which are ...


16

This will also fold in protection for the media request: var theURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem); mediaUrl = Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(theURL); Here is the link to Sitecore documentation that explains about protecting Sitecore media from abuse - https://doc.sitecore.net/...


14

You can use targetHostName setting in your site definition. It tells Link Manager to use that host name while generating url. It doesn't change the way how sites are resolved on your CM and CD servers. This only tells Sitecore to generate links using that particular host name for your site no matter if you're on CM or CD server. You can read more about ...


9

There is no out of the box way to make custom link manager configurations scope to a particular site, however you could always include that logic in the custom link manager itself. You can make your link manager resolve the site that a link is for. Then, if the resolved site is Site A then use the custom link manager logic; otherwise, if the resolved site is ...


8

Your problem is that Powershell is running in the context of the "shell" site, which gives you /sitecore/shell as the path. When using Sitecore.Links.LinkManager.GetItemUrl(), you'll need to be in the context of the site for which you want the URL. For this, you can use the SiteContextSwitcher, which can be used in a using block. In C#, you would do this as ...


8

You need register the new Media Manager using Sitecore Dependency Injection (see 'Registration in code' chapter). It can be done via Service Configurator as described in the article. Creating Service Configurator Implement Sitecore.DependencyInjection.IServicesConfigurator interface from Kernel assembly. Please note that you need to reference Microsoft ...


7

The use of SXA is rather important in this case. As you can see in your configuration, SXA uses by default the switchableLinkProvider. This will check your site configuration in Sitecore to determine if you defined a linkprovider there. If not (I assume you did not), it will take the fallback, which is defined here: <setting name="XA.Foundation....


7

With PowerShell you can use the New-UsingBlock cmdlet to mimick C#'s using statement. So assuming that you can use ancestors of the item to get the Site Root and then get the SiteContext from that you could do this to get the link: New-UsingBlock(New-Object -TypeName "Sitecore.Sites.SiteContextSwitcher" -ArgumentList $siteContext) { $linkUrl = [...


7

Let me start by saying that I believe that this is a bug in Sitecore, and the results of our peer debugging session have strengthened that belief. Solution/Workaround You should be able to work around this issue by adding an asterisk (*) to the hostName of the <site> definition node for your site, and leaving the targetHostName blank, as you ...


6

Best way to do this is by using physicalFolder/virtualFolder parameters in site definitions. step 1: Add seperate site definitions before "website" site definition as follows <site name="th-site" patch:before="site[@name='website']" virtualFolder="/th" physicalFolder="/th" rootPath="/sitecore/content" startItem="/Home" hostName="mysite....


6

If you're on Sitecore 8.2+, you can use abstract BaseLinkManager class (that's actually valid for all the old static managers). In combination with Sitecore Dependency Injection that is easy to inject the abstraction into a controller or a pipeline processor: public class MyController : ApiController { private readonly BaseLinkManager _linkManager; ...


5

I've had to add urlOptions.SiteResolving = true in my LinkProvider override and my GetItemUrl extension to get this to work properly. This is in Sitecore 8.2 and older versions, not sure about Sitecore 9.


5

You're still trying to generate link to the item version which is in your language. Try getting the other language version first: var otherLanguageVersion = Sitecore.Context.Item.Database.GetItem(Sitecore.Context.Item.ID, language); And then call: LinkManager.GetItemUrl(otherLanguageVersion, options);


5

Use this: Sitecore.Data.Fields.ImageField myImageItem = (Sitecore.Data.Fields.ImageField)Sitecore.Context.Item.Fields["MyImageField"]; then: Sitecore.Resources.Media.MediaManager.GetMediaUrl(myImageItem.MediaItem);


4

LinkManager is essentially just a static wrapper around LinkProvider, which uses virtual methods for everything. If you simply inject LinkManager.Provider into your controller's constructor, you can mock the LinkProvider in your tests.


4

Well, I've been in the archives ;-) Now I cannot say for sure, the solutions I list here will still be applicable in Sitecore 8. What I can say though, is that Sitecore will add LinkDB references to your fields and image items given that certain conditions are met: The Field Suite fields are defined in /App_Config/FieldTypes.config. Check this first. It ...


4

MediaManager has a GetMediaUrl method that can be used for this: Sitecore.Resources.Media.MediaManager.GetMediaUrl(MediaItem item); Sample usage: string mediaUrl = Sitecore.StringUtil.EnsurePrefix( '/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem));


4

From what I can find - the encodeNameReplacements are only used in MainUtil.DecodeName, MainUtil.EncodeName and MainUtil.EncodePath - These are used in both resolving url's and building them. So if the encoding is not there or if it encoded to something different it should still work ok. I could not find anything that explicitly set ,-d-, in the Url. ...


4

ItemSearchLinkProvider ItemSearchLinkProvider is a very simple provider with GetItemUrl method which: Checks if item is inside a bucket If no it returns base.GetUrl - where base class is Sitecore.Links.LinkProvider If yes, it generates url in a format: return string.Format("/{0}/{1}/{2}/{3}", item.GetParentBucketItemOrSiteRoot().Name.ToLower(), ...


3

For starters, you should use the Sitecore.Data.Fields.LinkField class and GetFriendlyUrl(). To rewrite what you have currently: public static string LinkFieldurl(this Item item, ID fieldID) { if (item == null) { return string.Empty; } if (ID.IsNullOrEmpty(fieldID)) { throw new ArgumentNullException(nameof(fieldID)); } ...


3

Sitecore support Sitecore recorded this as a bug. Patch can be found here https://github.com/SitecoreSupport/Sitecore.Support.170025 Self rolled code I was able to resolve this with code Hacky class to make the switch public static string ConvertHttpToHttps(string url) { if (Sitecore.Context.Site?.SiteInfo?.Scheme == "https") { if (...


3

After digging into the new Sitecore.Kernel assembly I have found the following way to get the default LinkProvider or your custom with the following appraches: To get default Sitecore.Links.LinkProvider: var defaultProvider = ServiceLocator.GetRequiredResetableService<ProviderHelper<Sitecore.Links.LinkProvider, LinkProviderCollection>>()?.Value?...


3

I feel like you may be switched around in your thinking. The display name field is used to when you view the item in sitecore you are able to have it look better compared to the actual item name. If you want to have urls created to look a certain way, it would be best to use the item name when you create the item to be the url you want and then fill out ...


3

As Marek mentioned, you should set @targetHostName on /configuration/sitecore/sites/site in your Sitecore.config. Furthermore, you should create your UrlOptions object like this: UrlOptions urlOptions = LinkManager.GetDefaultUrlOptions(); urlOptions.AlwaysIncludeServerUrl = true; This ensures that your code keeps using the settings of LinkManager, except ...


3

The vanilla Sitecore code to render a General Link field containing this external Url would be: LinkField lf = myitem.Fields["name of your field"]; string url = lf.GetFriendlyUrl(); You should verify this behaviour. It will either work as you expect, or it will be a bug in Sitecore. The string url should be exactly as given as value in the Sitecore client. ...


3

From what I understand, you want to implement custom logic for generation of internal links added by content authors in Rich Text fields. If that's the case, you need to change the logic of renderField pipeline and its ExpandLinks processor. By default this processor calls DynamicLink.ExpandLinks(...) method. You would need to replace that with your custom ...


3

The problem you are trying to solve, rendering the full URL with host name, does not require a custom link provider since this behaviour is available out of the box. There are 2 settings which control this, both of which are true by default in 9.3 (they have been true for a number of versions). <!-- SITE RESOLVING While rendering item links, some ...


2

Dug in a little and came across https://community.sitecore.net/developers/f/10/t/3721 Email Experience Manager 3.3.0 rev. 160527 It's look like a bug for multisite Sitecore environments. For generating url is called standard Sitecore method LinkManager.GetItemUrl, but EXM sends messages not in the main thread and do not have access to ...


2

For media items you should use the MediaManager to generate links instead of the LinkManager. The MediaManager will return a link to the actual media item. var urlOptions = new MediaUrlOptions(); urlOptions.Language = Language.Parse(item.Lang) var lnk = MediaManager.GetMediaUrl(item);


2

Usually this is just handled by adding canonical urls so Search engines know that the page is the same page even if referenced with upper/lowercase/displayname/trailing slash etc. This is not a Sitecore specific thing though. This article describes this further and how to implement this for Sitecore depending on your scenario: https://blog.mastykarz.nl/...


Only top voted, non community-wiki answers of a minimum length are eligible