我正在努力以计划作业的形式在Episerver中生成报告。该报告基本上用于在Episerver中获取所有内容(页面类型,块,媒体)。
有一些不错的nuget软件包用于内容用法,但出于某种原因&拥有更多控制权Tweeking&进一步扩展它,我正在创建一个自定义的,而不是使用可用的第三方软件包。
预定的工作类似于
。
这篇文章有助于我根据我的要求进行一些修改。
我在这里苦苦挣扎的一件事是获取块所在位置的URL。现在,这是这里的辩论。
我知道,自然界中共享的块可以在网站中的任何地方使用,但要点是它们仍在页面或事实上使用,而在其他块中,该块在页面上使用。在这里说,它们直接或间接是页面的一部分。因此,有没有一种方法可以获取块的页面URL,而不论其中有多少页。
我看过的每个论坛,总是有Page url of PageData或MediaData&在BlockData上没有任何内容。我所寻找的第三方Nuget软件包没有针对块类型的页面URL。
我确实知道这里没有什么开箱即用。
到达页面的递归功能:
private string GetPublicUrl(IContentRepository contentRepository, IContentSoftLinkRepository contentSoftLinkRepository, ContentReference contentReference)
{
var publicUrl = string.Empty;
var content = contentRepository.Get<IContent>(contentReference);
var referencingContentLinks = contentSoftLinkRepository.Load(content.ContentLink, true)
.Where(link => link.SoftLinkType == ReferenceType.PageLinkReference && !ContentReference.IsNullOrEmpty(link.OwnerContentLink))
.Select(link => link.OwnerContentLink);
foreach (var referencingContentLink in referencingContentLinks)
{
publicUrl = UrlResolver.Current.GetUrl(referencingContentLink.GetPublicUrl()) ?? GetPublicUrl(contentRepository, contentSoftLinkRepository, referencingContentLink);
}
return publicUrl;
}
我已经编写了此递归功能来到达页面,但是只有在一个级别的情况下才起作用。例如页面上的2Col块。
如果我有一个块Say下载块,该块在2Col块上又在页面上,那么在这种情况下,URL为空。
任何输入都将不胜感激。
I am working on generating a report in episerver in the form of a scheduled job.This report is basically used to get all the contents(page types,blocks,media) within Episerver.
There are some good nuget packages for content usages but for some reason& to have more control & plans for tweeking & extending it further,i am creating a custom one rather than using the available 3rd party packages.
The scheduled job is kind of similar to
https://www.codeart.dk/blog/2018/12/content-report-generator/ .
The article helped me a lot to get my report working with some modifications as per my requirement.
The one thing that I am struggling here is to get the URL of where the block is. Now this is a point of debate here.
I am aware that the blocks being shared in nature can be used anywhere in a site but the point is they are still used in pages or as a matter of fact in other blocks which is turn is used on a page.What i am trying to say here is,they directly or indirectly are part of a page.So is there a way to get the page url of a block irrespective of how many pages they are in.
Every forum I have looked at ,there's always page url of Pagedata or mediadata & nothing on blockdata.Even 3rd party nuget packages that i have looked for does not have page url for block types.
I do understand that there is nothing out of the box here.Is there a way to achieve this ie get the page url of a specific block type which can be a list of page urls if the block is used in multiple pages.
Recursive function to reach the page:
private string GetPublicUrl(IContentRepository contentRepository, IContentSoftLinkRepository contentSoftLinkRepository, ContentReference contentReference)
{
var publicUrl = string.Empty;
var content = contentRepository.Get<IContent>(contentReference);
var referencingContentLinks = contentSoftLinkRepository.Load(content.ContentLink, true)
.Where(link => link.SoftLinkType == ReferenceType.PageLinkReference && !ContentReference.IsNullOrEmpty(link.OwnerContentLink))
.Select(link => link.OwnerContentLink);
foreach (var referencingContentLink in referencingContentLinks)
{
publicUrl = UrlResolver.Current.GetUrl(referencingContentLink.GetPublicUrl()) ?? GetPublicUrl(contentRepository, contentSoftLinkRepository, referencingContentLink);
}
return publicUrl;
}
I have written this recursive function to reach the page ,but this works only when there is a single level. For instance A 2Col block on a page.
If I have a block say Download Block which is on a 2Col block which in turn is on a page ,then in this case the url is empty.
Any input is appreciated.
发布评论
评论(1)
使用
iContentsoftlinkrepository
您可以找到使用块的位置。您可以查看使用softlink.softlinktype == pagelinkreference
的软链接指向页面,然后使用iurlresolver
获取页面URL。With
IContentSoftLinkRepository
you can find where the blocks are used. You can check whether the SoftLink points to a page withSoftLink.SoftLinkType == PageLinkReference
and then useIUrlResolver
to get the page's URL.