当前位置: 首页>>代码示例>>C#>>正文


C# PublishedContentRequest.ConfigureRequest方法代码示例

本文整理汇总了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();
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:45,代码来源:EnsurePublishedContentRequestAttribute.cs


注:本文中的Umbraco.Web.Routing.PublishedContentRequest.ConfigureRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。