2011-05-25 54 views

回答

0

我剛剛在Stack Overflow上回答了a similar question。我相信這個答案也適用於你的。

簡短摘要:沒有配置要做到這一點,您需要重寫一些內置方法來執行此操作。請參閱上面的鏈接瞭解確切的細節。

3

我發現,下面將用於生產的媒體項目完全合格的網址的工作:

public static string GetMediaUrlWithServer(MediaItem mediaItem, Item item = null) 
{ 
    item = item ?? Sitecore.Context.Item; 
    var options = new UrlOptions {AlwaysIncludeServerUrl = true, AddAspxExtension = false}; 
    var itemUrl = LinkManager.GetItemUrl(item, options); 
    var mediaOptions = new MediaUrlOptions {AbsolutePath = true}; 
    var mediaUrl = MediaManager.GetMediaUrl(mediaItem, mediaOptions); 
    return itemUrl + mediaUrl; 
} 

生產的將是相對item的網址,所以你可能要參考提供給您的主頁,而不是項目的Sitecore.Context.Item

8

就碰到這件事,在Sitecore的7也被包括在MediaUrlOptionsAlwaysIncludeServerUrl選項(我不知道,因爲這Sitecore的版本)

喜歡分享:

MediaUrlOptions muo = new MediaUrlOptions(); 
muo.AlwaysIncludeServerUrl = true; 
String url = MediaManager.GetMediaUrl((MediaItem)item, muo); 
0

是的,你可以做到這一點!

設置此參數的正確方法是在配置文件中指定linkManager部分,您可以在此處瞭解有關如何解析URL的其餘設置。這裏是整段,你在有興趣alwaysIncludeServerUrl參數:

<linkManager defaultProvider="sitecore"> 
    <providers> 
    <clear /> 
    <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" 
     alwaysIncludeServerUrl="true"    
     addAspxExtension="true" 
     encodeNames="true" 
     languageEmbedding="asNeeded" 
     languageLocation="filePath" 
     shortenUrls="true" 
     useDisplayName="false" /> 
    </providers> 
</linkManager> 
+3

不要以爲這適用於MediaManager.GetMediaUrl – 2015-08-06 21:44:28