View Alternate にいるときは、次を使用して ContentItem の表示 URL を取得できることを知っています。
@Url.ItemDisplayUrl(contentItem)
しかし、コントローラー コンテキスト (ActionResult) にいるときに表示 URL を取得する方法がわかりません。サイトマップの目的で、リストされている ContentItems の URL が必要です。
以下のコードを使用しています。
public class SiteMapResult : ActionResult
{
readonly IContentManager _contentManager;
readonly ITagService _tagService;
public SiteMapXmlResult(IContentManager contentManager, ITagService tagService)
{
_contentManager = contentManager;
_tagService = tagService;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/xml";
string host = context.HttpContext.Request.Url.Host;
StringBuilder xml = new StringBuilder();
xml.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
xml.Append(@"<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">");
var contentItems = _contentManager.Query(VersionOptions.Latest, GetContentTypeNames().ToArray()).List();
foreach (var contentItem in contentItems)
{
// The display url of contentItem
}
...
}
}
ContentItem の表示 URL を取得するにはどうすればよいですか?