本文整理汇总了C#中IDocumentSession.GetPublishedPages方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentSession.GetPublishedPages方法的具体用法?C# IDocumentSession.GetPublishedPages怎么用?C# IDocumentSession.GetPublishedPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocumentSession
的用法示例。
在下文中一共展示了IDocumentSession.GetPublishedPages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolvePath
/// <summary>
/// Resolves the path.
/// </summary>
/// <param name="routeData">The route data.</param>
/// <param name="virtualUrl">The virtual URL.</param>
/// <returns></returns>
public IPathData ResolvePath(RouteData routeData, string virtualUrl)
{
// Set the default action to index
_pathData.Action = UIRoute.DefaultAction;
// Get an up to date document session from structuremap
_session = _container.GetInstance<IDocumentSession>();
// The requested url is for the start page with no action
if (string.IsNullOrEmpty(virtualUrl) || string.Equals(virtualUrl, "/")) {
_pageModel = _session.Query<IPageModel>()
.Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
.SingleOrDefault(x => x.Parent == null);
} else {
// Remove the trailing slash
virtualUrl = VirtualPathUtility.RemoveTrailingSlash(virtualUrl).TrimStart(new[] { '/' });
// The normal beahaviour should be to load the page based on the url
_pageModel = _session.Query<IPageModel, PageByUrl>()
.Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
.FirstOrDefault(x => x.Metadata.Url == virtualUrl);
// Try to load the page without the last segment of the url and set the last segment as action))
if (_pageModel == null && virtualUrl.LastIndexOf("/") > 0) {
var index = virtualUrl.LastIndexOf("/");
var action = virtualUrl.Substring(index, virtualUrl.Length - index).Trim(new[] { '/' });
virtualUrl = virtualUrl.Substring(0, index).TrimStart(new[] { '/' });
_pageModel = _session.Query<IPageModel, PageByUrl>()
.Customize(x => x.WaitForNonStaleResultsAsOfLastWrite())
.FirstOrDefault(x => x.Metadata.Url == virtualUrl);
_pathData.Action = action;
}
// If the page model still is empty, let's try to resolve if the start page has an action named (virtualUrl)
if (_pageModel == null) {
_pageModel = _session.Query<IPageModel>().SingleOrDefault(x => x.Parent == null);
if(_pageModel == null) {
return null;
}
var pageTypeAttribute = _pageModel.GetType().GetAttribute<PageTypeAttribute>();
object area;
_controllerName = _controllerMapper.GetControllerName(routeData.Values.TryGetValue("area", out area) ? typeof(PagesController) : pageTypeAttribute.ControllerType);
var action = virtualUrl.TrimStart(new[] { '/' });
if (!_controllerMapper.ControllerHasAction(_controllerName, action)) {
return null;
}
_pathData.Action = action;
}
}
if (_pageModel == null) {
return null;
}
var controllerType = _pageModel.GetType().GetAttribute<PageTypeAttribute>().ControllerType;
_pathData.Controller = controllerType != null ? _controllerMapper.GetControllerName(controllerType) : string.Format("{0}Controller", _pageModel.GetType().Name);
_pathData.CurrentPage = _pageModel;
_pathData.NavigationContext = _session.GetPublishedPages(_pageModel.Id);
return _pathData;
}