本文整理汇总了C#中Umbraco.Web.Routing.PublishedContentRequest.ConfigureRequest方法的典型用法代码示例。如果您正苦于以下问题:C# PublishedContentRequest.ConfigureRequest方法的具体用法?C# PublishedContentRequest.ConfigureRequest怎么用?C# PublishedContentRequest.ConfigureRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Umbraco.Web.Routing.PublishedContentRequest
的用法示例。
在下文中一共展示了PublishedContentRequest.ConfigureRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigurePublishedContentRequest
/// <summary>
/// This assigns the published content to the request, developers can override this to specify
/// any other custom attributes required.
/// </summary>
/// <param name="pcr"></param>
/// <param name="filterContext"></param>
protected virtual void ConfigurePublishedContentRequest(PublishedContentRequest pcr, ActionExecutedContext filterContext)
{
if (_contentId.HasValue)
{
var content = Umbraco.TypedContent(_contentId);
if (content == null)
{
throw new InvalidOperationException("Could not resolve content with id " + _contentId);
}
pcr.PublishedContent = content;
}
else if (_dataTokenName.IsNullOrWhiteSpace() == false)
{
var result = filterContext.RouteData.DataTokens[_dataTokenName];
if (result == null)
{
throw new InvalidOperationException("No data token could be found with the name " + _dataTokenName);
}
if ((result is IPublishedContent) == false)
{
throw new InvalidOperationException("The data token resolved with name " + _dataTokenName + " was not an instance of " + typeof(IPublishedContent));
}
pcr.PublishedContent = (IPublishedContent) result;
}
//need to set the culture for this to work
if (_culture.IsNullOrWhiteSpace())
{
//none specified so get the default
var defaultLanguage = Language.GetAllAsList().FirstOrDefault();
pcr.Culture = defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.CultureAlias);
}
else
{
pcr.Culture = new CultureInfo(_culture);
}
pcr.ConfigureRequest();
}