Skip to main content
18 votes

How do you get the link for a media item?

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); ...
zzzzBov's user avatar
  • 873
17 votes
Accepted

How do you get the link for a media item?

This will also fold in protection for the media request: var theURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem); mediaUrl = Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(...
G Killian's user avatar
  • 1,309
14 votes
Accepted

Create link as CD from CM

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 ...
Marek Musielak's user avatar
  • 23.8k
10 votes
Accepted

Is there any way to add the custom Link manager provider just for a particular site

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 ...
Zachary Kniebel's user avatar
9 votes
Accepted

Sitecore LinkManager in PowerShell generate wrong protocol

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 ...
Matthew FitzGerald-Chamberlain's user avatar
8 votes
Accepted

Override Media Manager to Change Url

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 ...
Serhii Shushliapin's user avatar
7 votes
Accepted

Omit bucket folders from page urls - linkprovider not working in SXA

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 ...
Gatogordo's user avatar
  • 20.1k
7 votes
Accepted

Create Sitecore Link with Powershell

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 ...
Richard Seal's user avatar
  • 20.4k
7 votes
Accepted

LinkManager returning inconsistent Server Url

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 ...
Zachary Kniebel's user avatar
6 votes

How to change language code in URL

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-...
scFootsteps's user avatar
  • 3,851
6 votes

How to get item url without using Linkmanager?

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 ...
Serhii Shushliapin's user avatar
5 votes
Accepted

Sitecore multisite cross links not resolved with proper hostname

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 ...
Melanie's user avatar
  • 66
5 votes
Accepted

Language specific URLs with UseDisplayName and LinkManager

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(...
Marek Musielak's user avatar
  • 23.8k
5 votes

How do you get the link for a media item?

Use this: Sitecore.Data.Fields.ImageField myImageItem = (Sitecore.Data.Fields.ImageField)Sitecore.Context.Item.Fields["MyImageField"]; then: Sitecore.Resources.Media.MediaManager.GetMediaUrl(...
Sergey Kravchenko's user avatar
4 votes
Accepted

How to get item url without using Linkmanager?

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 ...
Richard Szalay's user avatar
4 votes
Accepted

Save multi values to image library with link reference

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 ...
Mark Cassidy's user avatar
  • 25.2k
4 votes

How do you get the link for a media item?

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( ...
Ed Schwehm's user avatar
  • 3,036
4 votes
Accepted

Ramifications of removing encodeNameReplacement for dot (.)

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 ...
Richard Seal's user avatar
  • 20.4k
4 votes
Accepted

When should I use ScalableLinkProvider or ItemSearchLinkProvider?

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....
Marek Musielak's user avatar
  • 23.8k
4 votes

How to get URLS added in the Rich Text field and Link Manager Fields?

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 ...
Marek Musielak's user avatar
  • 23.8k
3 votes

Multilingual - Sitecore General Link Field Url Giving Embedded Language in Wrong Format

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 (...
George Chang's user avatar
  • 1,225
3 votes
Accepted

LinkManager.Provider is deprecated in Sitecore 9, how to get the default provider then?

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....
Tamás Tárnok's user avatar
3 votes
Accepted

Is it possible to move "Display name" out of standard fields?

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 ...
Meredori's user avatar
  • 146
3 votes

Create link as CD from CM

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 ...
LaustN's user avatar
  • 335
3 votes
Accepted

Media Provider ignoring site scheme setting

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 ...
Chris Auer's user avatar
  • 13.1k
3 votes
Accepted

Render a link field that has a url with query params as a query param (version 7.2)

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 ...
Mark Cassidy's user avatar
  • 25.2k
3 votes
Accepted

LinkManager.ResolveTargetSite is obsolete - what is the replacement

I think its a typo in the obsolete message and they want you to use the IItemSiteResolver instead. If you follow the LinkManager.ResolveTargetSite code through, eventually it gets to this method: [...
Richard Seal's user avatar
  • 20.4k
3 votes
Accepted

Sitecore 9.3 CustomLinkProvider

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 ...
jammykam's user avatar
  • 13.8k
2 votes

LinkManager returning inconsistent Server Url

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 ...
vandsh's user avatar
  • 1,651
2 votes

Cache problems when generating links with the LinkManager class

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(); ...
Richard Seal's user avatar
  • 20.4k

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