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


C# Routing.PublishedContentRequest类代码示例

本文整理汇总了C#中Umbraco.Web.Routing.PublishedContentRequest的典型用法代码示例。如果您正苦于以下问题:C# PublishedContentRequest类的具体用法?C# PublishedContentRequest怎么用?C# PublishedContentRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PublishedContentRequest类属于Umbraco.Web.Routing命名空间,在下文中一共展示了PublishedContentRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnPreInit

		protected override void OnPreInit(EventArgs e)
		{
			base.OnPreInit(e);

			// handle the infamous umbDebugShowTrace, etc
			Page.Trace.IsEnabled &= GlobalSettings.DebugMode && !String.IsNullOrWhiteSpace(Request["umbDebugShowTrace"]);

			// get the document request and the page
			_docRequest = UmbracoContext.Current.PublishedContentRequest;
			_upage = _docRequest.UmbracoPage;

			//we need to check this for backwards compatibility in case people still arent' using master pages
			if (UmbracoSettings.UseAspNetMasterPages)
			{
				var args = new RequestInitEventArgs()
				{
					Page = _upage,
					PageId = _upage.PageID,
					Context = Context
				};
				FireBeforeRequestInit(args);

				//if we are cancelling then return and don't proceed
				if (args.Cancel) return;

				this.MasterPageFile = template.GetMasterPageName(_upage.Template);

				// reset the friendly path so it's used by forms, etc.			
				Context.RewritePath(UmbracoContext.Current.OriginalRequestUrl.PathAndQuery);

				//fire the init finished event
				FireAfterRequestInit(args);	
			}
			
		}
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:35,代码来源:default.aspx.cs

示例2: TryFindContent

		/// <summary>
		/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
		/// </summary>
		/// <param name="docRequest">The <c>PublishedContentRequest</c>.</param>		
		/// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
		public bool TryFindContent(PublishedContentRequest docRequest)
        {
            IPublishedContent node = null;
			var path = docRequest.Uri.GetAbsolutePathDecoded();

            var nodeId = -1;
			if (path != "/") // no id if "/"
            {
				var noSlashPath = path.Substring(1);

                if (!Int32.TryParse(noSlashPath, out nodeId))
                    nodeId = -1;

                if (nodeId > 0)
                {
					LogHelper.Debug<ContentFinderByIdPath>("Id={0}", () => nodeId);
                    node = docRequest.RoutingContext.UmbracoContext.ContentCache.GetById(nodeId);

                    if (node != null)
                    {
						docRequest.PublishedContent = node;
						LogHelper.Debug<ContentFinderByIdPath>("Found node with id={0}", () => docRequest.PublishedContent.Id);
                    }
                    else
                    {
                        nodeId = -1; // trigger message below
                    }
                }
            }

            if (nodeId == -1)
				LogHelper.Debug<ContentFinderByIdPath>("Not a node id");

            return node != null;
        }
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:40,代码来源:ContentFinderByIdPath.cs

示例3: Lookup_By_Url_Alias_And_Domain

        [TestCase("http://domain1.com/en/bar/nil", "en-US", 100111)] // ok, alias includes "en/"
        public void Lookup_By_Url_Alias_And_Domain(string inputUrl, string expectedCulture, int expectedNode)
        {
            SetDomains1();

            var routingContext = GetRoutingContext(inputUrl);
            var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
            var pcr = new PublishedContentRequest(url, routingContext);
            // must lookup domain
            pcr.Engine.FindDomain();

            if (expectedNode > 0)
                Assert.AreEqual(expectedCulture, pcr.Culture.Name);

            var finder = new ContentFinderByUrlAlias();
            var result = finder.TryFindContent(pcr);

            if (expectedNode > 0)
            {
                Assert.IsTrue(result);
                Assert.AreEqual(pcr.PublishedContent.Id, expectedNode);
            }
            else
            {
                Assert.IsFalse(result);
            }
        }
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:27,代码来源:ContentFinderByAliasWithDomainsTests.cs

示例4: PublishedContentRequestBuilder

		public PublishedContentRequestBuilder(PublishedContentRequest publishedContentRequest)
		{
			if (publishedContentRequest == null) throw new ArgumentNullException("publishedContentRequest");
			_publishedContentRequest = publishedContentRequest;
			_umbracoContext = publishedContentRequest.RoutingContext.UmbracoContext;
			_routingContext = publishedContentRequest.RoutingContext;
		}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:7,代码来源:PublishedContentRequestBuilder.cs

示例5: TryFindContent

        /// <summary>
        /// For each request, this function checks to see if its a virtual Blog URL targeted to 
        /// Authors, Categories, Tags & RSS and routes accordingly
        /// </summary>
        /// <param name="contentRequest"></param>
        /// <returns>True for a virtual URL or false for an exsting CMS Page</returns>
        public bool TryFindContent(PublishedContentRequest contentRequest)
        {
            string fullUri = contentRequest.Uri.AbsolutePath;
            Regex reg = new Regex("author|category|tag|rss");
            if (reg.IsMatch(fullUri)) { //Simple regex match to see if it's a possible url to redirect. If not, lets not worry about the overhead and just return false
                if (uQuery.GetNodesByType("BlogEntry").Where(r => r.Url.StartsWith(fullUri, StringComparison.InvariantCultureIgnoreCase)).Count() > 0) {
                    //We've found a match to a blog entry, so no need to redirect

                    return false;
                }

                //Get All Blog listings. This should only be a handful at Max
                var allNodes = uQuery.GetNodesByType("BlogListing").OrderByDescending(n => n.Level);

                foreach (var node in allNodes) {

                    string parentUri = node.Url;
                    bool isChild = fullUri.StartsWith(parentUri, StringComparison.InvariantCultureIgnoreCase);

                    if (isChild) {
                        //Its a virtual URL that is a child of a Blog listing.
                        contentRequest.PublishedContent = new UmbracoHelper(UmbracoContext.Current).TypedContent(node.Id);

                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:DigitalMomentum,项目名称:BlogMomentum,代码行数:36,代码来源:ContentFinder.cs

示例6: TrySetDocument

        /// <summary>
        /// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
        /// </summary>
        /// <param name="pcr">The <c>PublishedContentRequest</c>.</param>		
        /// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
        public bool TrySetDocument(PublishedContentRequest pcr)
        {
            LogHelper.Debug<LookupByLegacy404>("Looking for a page to handle 404.");

            // TODO - replace the whole logic and stop calling into library!
            var error404 = global::umbraco.library.GetCurrentNotFoundPageId();
            var id = int.Parse(error404);

            IPublishedContent content = null;

            if (id > 0)
            {
                LogHelper.Debug<LookupByLegacy404>("Got id={0}.", () => id);

                content = pcr.RoutingContext.PublishedContentStore.GetDocumentById(
                        pcr.RoutingContext.UmbracoContext,
                        id);

                if (content == null)
                    LogHelper.Debug<LookupByLegacy404>("Could not find content with that id.");
                else
                    LogHelper.Debug<LookupByLegacy404>("Found corresponding content.");
            }
            else
            {
                LogHelper.Debug<LookupByLegacy404>("Got nothing.");
            }

            pcr.PublishedContent = content;
            pcr.Is404 = true;
            return content != null;
        }
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:37,代码来源:LookupByLegacy404.cs

示例7: LookupDocumentNode

		/// <summary>
		/// Tries to find an Umbraco document for a <c>PublishedContentRequest</c> and a route.
		/// </summary>
		/// <param name="docreq">The document request.</param>
		/// <param name="route">The route.</param>
		/// <returns>The document node, or null.</returns>
        protected IPublishedContent LookupDocumentNode(PublishedContentRequest docreq, string route)
        {
			LogHelper.Debug<LookupByNiceUrl>("Test route \"{0}\"", () => route);

			// first ask the cache for a node
			// return '0' if in preview mode
        	var nodeId = !docreq.RoutingContext.UmbracoContext.InPreviewMode
							? docreq.RoutingContext.UmbracoContext.RoutesCache.GetNodeId(route)
        	             	: 0;

			// if a node was found, get it by id and ensure it exists
			// else clear the cache
            IPublishedContent node = null;
            if (nodeId > 0)
            {
				node = docreq.RoutingContext.PublishedContentStore.GetDocumentById(
					docreq.RoutingContext.UmbracoContext,
					nodeId);

                if (node != null)
                {
                    docreq.PublishedContent = node;
					LogHelper.Debug<LookupByNiceUrl>("Cache hit, id={0}", () => nodeId);
                }
                else
                {
                    docreq.RoutingContext.UmbracoContext.RoutesCache.ClearNode(nodeId);
                }
            }

			// if we still have no node, get it by route
            if (node == null)
            {
				LogHelper.Debug<LookupByNiceUrl>("Cache miss, query");
				node = docreq.RoutingContext.PublishedContentStore.GetDocumentByRoute(
					docreq.RoutingContext.UmbracoContext,
					route);

                if (node != null)
                {
                    docreq.PublishedContent = node;
					LogHelper.Debug<LookupByNiceUrl>("Query matches, id={0}", () => docreq.DocumentId);

					var iscanon = _doDomainLookup && !DomainHelper.ExistsDomainInPath(docreq.Domain, node.Path);
					if (!iscanon)
						LogHelper.Debug<LookupByNiceUrl>("Non canonical url");

					// do not store if previewing or if non-canonical
					if (!docreq.RoutingContext.UmbracoContext.InPreviewMode && iscanon)
						docreq.RoutingContext.UmbracoContext.RoutesCache.Store(docreq.DocumentId, route);
                    
                }
                else
                {
					LogHelper.Debug<LookupByNiceUrl>("Query does not match");
                }
            }

            return node;
        }
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:66,代码来源:LookupByNiceUrl.cs

示例8: TrySetDocument

	    /// <summary>
		/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
		/// </summary>
		/// <param name="docRequest">The <c>PublishedContentRequest</c>.</param>		
		/// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
		public virtual bool TrySetDocument(PublishedContentRequest docRequest)
        {
			string route;
			if (docRequest.HasDomain)
				route = docRequest.Domain.RootNodeId.ToString() + DomainHelper.PathRelativeToDomain(docRequest.DomainUri, docRequest.Uri.GetAbsolutePathDecoded());
			else
				route = docRequest.Uri.GetAbsolutePathDecoded();

			var node = LookupDocumentNode(docRequest, route);
            return node != null;
        }
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:16,代码来源:LookupByNiceUrl.cs

示例9: TryFindContent

        public override bool TryFindContent(PublishedContentRequest contentRequest)
        {
            // eg / or /path/to/whatever
            var url = contentRequest.Uri.GetAbsolutePathDecoded();

            var mdRoot = "/" + MarkdownLogic.BaseUrl;
            if (url.StartsWith("/projects/umbraco-pro/contour/documentation"))
                mdRoot = "/projects";

            // ensure it's a md url
            if (url.StartsWith(mdRoot) == false)
                return false; // not for us

            // find the root content
            var node = FindContent(contentRequest, mdRoot);
            if (node == null)
                return false;

            // kill those old urls
            foreach (var s in new []{ "master", "v480" })
                if (url.StartsWith(mdRoot + "/" + s))
                {
                    url = url.Replace(mdRoot + "/" + s, mdRoot);
                    contentRequest.SetRedirectPermanent(url);
                    return true;
                }

            // find the md file
            var mdFilepath = FindMarkdownFile(url);
            if (mdFilepath == null)
            {
                // clear the published content (that was set by FindContent) to cause a 404, and in
                // both case return 'true' because there's no point other finders try to handle the request
                contentRequest.PublishedContent = null;
                return true;
            }

            // set the context vars
            var httpContext = contentRequest.RoutingContext.UmbracoContext.HttpContext;
            httpContext.Items[MarkdownLogic.MarkdownPathKey] = mdFilepath;
            httpContext.Items["topicTitle"] = string.Join(" - ", httpContext.Request.RawUrl
                .Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
                .Skip(1)
                .Reverse());

            // override the template
            const string altTemplate = "DocumentationSubpage";
            var templateIsSet = contentRequest.TrySetTemplate(altTemplate);
            //httpContext.Trace.Write("Markdown Files Handler",
            //    string.Format("Template changed to: '{0}' is {1}", altTemplate, templateIsSet));

            // be happy
            return true;
        }
开发者ID:KerwinMa,项目名称:OurUmbraco,代码行数:54,代码来源:DocumentationContentFinder.cs

示例10: PreparePublishedContentRequest

        //NOTE: This is the manual way we could assign culture this but I think there's more logic for edge case scenarios in Umbraco's Prepare method.
        // I've just left this code here as an example
        protected override void PreparePublishedContentRequest(PublishedContentRequest publishedContentRequest)
        {
            //if (_hostsAndIds.Any(x => x.Item2 == publishedContentRequest.PublishedContent.Parent.Id))
            //{
            //    var hostAndId = _hostsAndIds.Single(x => x.Item2 == publishedContentRequest.PublishedContent.Parent.Id);
            //    var domain = Domain.GetDomain(hostAndId.Item1);
            //    publishedContentRequest.Culture = new CultureInfo(domain.Language.CultureAlias);
            //}

            base.PreparePublishedContentRequest(publishedContentRequest);

        }
开发者ID:ryan-buckman,项目名称:Dialogue,代码行数:14,代码来源:UmbracoVirtualNodeByIdRouteHandler.cs

示例11: Lookup_By_Url_Alias

		public void Lookup_By_Url_Alias(string urlAsString, int nodeMatch)
		{
			var routingContext = GetRoutingContext(urlAsString);
			var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
			var docRequest = new PublishedContentRequest(url, routingContext);
			var lookup = new LookupByAlias();
			
			var result = lookup.TrySetDocument(docRequest);

			Assert.IsTrue(result);
			Assert.AreEqual(docRequest.DocumentId, nodeMatch);
		}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:12,代码来源:LookupByAliasTests.cs

示例12: GetTemplateAliasByContentAccept

 private string GetTemplateAliasByContentAccept(PublishedContentRequest docRequest)
 {
     HttpContext context = HttpContext.Current;
     string template = null;
     if (ConfigurationManager.AppSettings.AllKeys.Contains("WG2K.Hypermedia.Templates." + context.Request.ContentType))
         template = ConfigurationManager.AppSettings["WG2K.Hypermedia.Templates." + context.Request.ContentType];
     if (template != null)
     {
         return template;
     }
     return "unknown";
 }
开发者ID:biapar,项目名称:uhateoas,代码行数:12,代码来源:ContentFinderByNiceUrlWithContentAccept.cs

示例13: Match_Document_By_Url

		public void Match_Document_By_Url(string urlString, int expectedId)
		{
			var routingContext = GetRoutingContext(urlString);
			var url = routingContext.UmbracoContext.CleanedUmbracoUrl;	//very important to use the cleaned up umbraco url		
			var docreq = new PublishedContentRequest(url, routingContext);			
			var lookup = new LookupByNiceUrl();

			var result = lookup.TrySetDocument(docreq);

			Assert.IsTrue(result);
			Assert.AreEqual(expectedId, docreq.DocumentId);
		}
开发者ID:elrute,项目名称:Triphulcas,代码行数:12,代码来源:LookupByNiceUrlTests.cs

示例14: PublishedContentRequestEngine

		/// <summary>
		/// Initializes a new instance of the <see cref="PublishedContentRequestEngine"/> class with a content request.
		/// </summary>
		/// <param name="pcr">The content request.</param>
		public PublishedContentRequestEngine(PublishedContentRequest pcr)
		{
			_pcr = pcr;
			_routingContext = pcr.RoutingContext;

			var umbracoContext = _routingContext.UmbracoContext;
			if (_routingContext == null) throw new ArgumentException("pcr.RoutingContext is null.");
			if (umbracoContext == null) throw new ArgumentException("pcr.RoutingContext.UmbracoContext is null.");
			if (umbracoContext.RoutingContext != _routingContext) throw new ArgumentException("RoutingContext confusion.");
			// no! not set yet.
			//if (umbracoContext.PublishedContentRequest != _pcr) throw new ArgumentException("PublishedContentRequest confusion.");
		}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:16,代码来源:PublishedContentRequestEngine.cs

示例15: Lookup_By_Id

		public void Lookup_By_Id(string urlAsString, int nodeMatch)
		{
			var routingContext = GetRoutingContext(urlAsString);
			var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
			var docRequest = new PublishedContentRequest(url, routingContext);
			var lookup = new ContentFinderByIdPath();
		

			var result = lookup.TryFindContent(docRequest);

			Assert.IsTrue(result);
			Assert.AreEqual(docRequest.PublishedContent.Id, nodeMatch);
		}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:13,代码来源:ContentFinderByIdTests.cs


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