简体   繁体   English

如何在sitecore rss提要中获取媒体链接

[英]How to get media link in sitecore rss feed

I am setting a feed for media items in sitecore and followed the setup guide and everything works ok.我正在为 sitecore 中的媒体项目设置提要,并按照设置指南进行操作,一切正常。 However, the link tag in the feed generates the absolute path to the media item in the content tree, something like this但是,提要中的链接标签生成内容树中媒体项的绝对路径,类似于

在此处输入图片说明

What we want is the url to the image on the server like http://ecms-site1.intlsos.com/-/media/corporate/..../incident-occurs.mp3我们想要的是服务器上图像的 url,如http://ecms-site1.intlsos.com/-/media/corporate/..../incident-occurs.mp3

I inherited from PublicFeed class to add extra property in the rss feed, but need help changing the behaviour of the link property to return the media url.我继承自 PublicFeed 类以在 rss 提要中添加额外的属性,但需要帮助更改链接属性的行为以返回媒体 url。

thanks谢谢

For media items you should use Sitecore MediaManager, not LinkManager as for ordinary pages, and specify MediaUrlOptions to control absolute and relative URLs for your media assets.对于媒体项目,您应该使用 Sitecore MediaManager,而不是像普通页面那样使用 LinkManager,并指定 MediaUrlOptions 来控制媒体资产的绝对和相对 URL。 The below code defines an extension for a Sitecore media item to generate an absolute URL for it:以下代码定义了 Sitecore 媒体项目的扩展,以为其生成绝对 URL:

using Sitecore.Resources.Media;

public static string AbsoluteMediaItemUrl(this Sitecore.Data.Items.MediaItem item)
            {
                MediaUrlOptions mediaUrlOptions = new MediaUrlOptions
                {
                    AlwaysIncludeServerUrl = true,
                    AbsolutePath = true
                };
                return MediaManager.GetMediaUrl(item, mediaUrlOptions);
            }

In order to override the standard RSS feed functionality in Sitecore you have to create your custom class inherited from Sitecore.Syndication.PublicFeed and override SyndicationItem RenderItem(Item item) method.为了覆盖 Sitecore 中的标准 RSS 提要功能,您必须创建从Sitecore.Syndication.PublicFeed继承的自定义类并覆盖SyndicationItem RenderItem(Item item)方法。 Next you require to map your newly created class to your RSS Feed Item in Sitecore to specify what custom class you want to reference to instead of the standard PublicFeed one.接下来,您需要将新创建的类映射到 Sitecore 中的 RSS Feed 项,以指定要引用的自定义类,而不是标准的 PublicFeed 类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM