當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。