예제 #1
0
		public void DoNotPolluteCache()
		{
            SettingsForTests.UseDirectoryUrls = true;
            SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains
            SettingsForTests.UseDomainPrefixes = false;

			InitializeLanguagesAndDomains();
			SetDomains1();

			RoutingContext routingContext;
			string url = "http://domain1.com/1001-1/1001-1-1";
			
			// get the nice url for 100111
			routingContext = GetRoutingContext(url);
			Assert.AreEqual("http://domain2.com/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111, true));

			// check that the proper route has been cached
			var cachedRoutes = ((DefaultRoutesCache)routingContext.UmbracoContext.RoutesCache).GetCachedRoutes();
			Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]);

			// route a rogue url
			url = "http://domain1.com/1001-1/1001-1-1";
			var uri = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
			var docreq = new PublishedContentRequest(uri, routingContext);
			var builder = new PublishedContentRequestBuilder(docreq);
			builder.LookupDomain();
			Assert.IsTrue(docreq.HasDomain);

			// check that it's been routed
			var lookup = new LookupByNiceUrl();
			var result = lookup.TrySetDocument(docreq);
			Assert.IsTrue(result);
			Assert.AreEqual(100111, docreq.DocumentId);

			// has the cache been polluted?
			cachedRoutes = ((DefaultRoutesCache)routingContext.UmbracoContext.RoutesCache).GetCachedRoutes();
			Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]); // no
			//Assert.AreEqual("1001/1001-1/1001-1-1", cachedRoutes[100111]); // yes

			// what's the nice url now?
			Assert.AreEqual("http://domain2.com/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111)); // good
			//Assert.AreEqual("http://domain1.com/1001-1/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // bad
		}
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PublishedContentRequest"/> class with a specific Uri and routing context.
        /// </summary>
        /// <param name="uri">The request <c>Uri</c>.</param>
        /// <param name="routingContext">A routing context.</param>
        public PublishedContentRequest(Uri uri, RoutingContext routingContext)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (routingContext == null)
            {
                throw new ArgumentNullException("routingContext");
            }

            this.Uri            = uri;
            this.RoutingContext = routingContext;

            _builder = new PublishedContentRequestBuilder(this);

            // set default
            this.RenderingEngine = RenderingEngine.Mvc;
        }
예제 #3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="PublishedContentRequest"/> class with a specific Uri and routing context.
		/// </summary>
		/// <param name="uri">The request <c>Uri</c>.</param>
		/// <param name="routingContext">A routing context.</param>
		public PublishedContentRequest(Uri uri, RoutingContext routingContext)
        {
			if (uri == null) throw new ArgumentNullException("uri");
			if (routingContext == null) throw new ArgumentNullException("routingContext");

			this.Uri = uri;
			this.RoutingContext = routingContext;

			_builder = new PublishedContentRequestBuilder(this);
			
			// set default
			this.RenderingEngine = RenderingEngine.Mvc;			
        }
예제 #4
0
		public void Render(StringWriter writer)
		{
			if (writer == null) throw new ArgumentNullException("writer");
			// instanciate a request a process
			// important to use CleanedUmbracoUrl - lowercase path-only version of the current url, though this isn't going to matter
			// terribly much for this implementation since we are just creating a doc content request to modify it's properties manually.
			var contentRequest = new PublishedContentRequest(_umbracoContext.CleanedUmbracoUrl, _umbracoContext.RoutingContext);
			
			var doc = contentRequest.RoutingContext.PublishedContentStore.GetDocumentById(
					contentRequest.RoutingContext.UmbracoContext,
					PageId);

			if (doc == null)
			{
				writer.Write("<!-- Could not render template for Id {0}, the document was not found -->", PageId);
				return;
			}

            //in some cases the UmbracoContext will not have a PublishedContentRequest assigned to it if we are not in the
            //execution of a front-end rendered page. In this case set the culture to the default.
            //set the culture to the same as is currently rendering
            if (_umbracoContext.PublishedContentRequest == null)
            {
                var defaultLanguage = Language.GetAllAsList().FirstOrDefault();
                contentRequest.Culture = defaultLanguage == null 
                    ? CultureInfo.CurrentUICulture 
                    : new CultureInfo(defaultLanguage.CultureAlias);
            }
            else
            {
                contentRequest.Culture = _umbracoContext.PublishedContentRequest.Culture;    
            }
			
			//set the doc that was found by id
			contentRequest.PublishedContent = doc;
			//set the template, either based on the AltTemplate found or the standard template of the doc
			contentRequest.Template = !AltTemplate.HasValue 
				? global::umbraco.cms.businesslogic.template.Template.GetTemplate(doc.TemplateId)
				: global::umbraco.cms.businesslogic.template.Template.GetTemplate(AltTemplate.Value);

			//if there is not template then exit
			if (!contentRequest.HasTemplate)
			{
				if (!AltTemplate.HasValue)
				{
					writer.Write("<!-- Could not render template for Id {0}, the document's template was not found with id {0}-->", doc.TemplateId);	
				}				
				else
				{
					writer.Write("<!-- Could not render template for Id {0}, the altTemplate was not found with id {0}-->", AltTemplate);	
				}
				return;
			}

			//ok, we have a document and a template assigned, now to do some rendering.
			var builder = new PublishedContentRequestBuilder(contentRequest);
			//determine the rendering engine
			builder.DetermineRenderingEngine();

			//First, save all of the items locally that we know are used in the chain of execution, we'll need to restore these
			//after this page has rendered.
			SaveExistingItems();

			//set the new items on context objects for this templates execution
			SetNewItemsOnContextObjects(contentRequest);

			//Render the template
			ExecuteTemplateRendering(writer, contentRequest);

			//restore items on context objects to continuing rendering the parent template
			RestoreItems();
		}
		[TestCase("https://domain3.com/", 1001, "en-US")] // because domain3 is explicitely set on http

		public void Lookup_NestedDomains(string url, int expectedId, string expectedCulture)
		{
			SetDomains4();

			SettingsForTests.HideTopLevelNodeFromPath = true;

			var routingContext = GetRoutingContext(url);
			var uri = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
			var docreq = new PublishedContentRequest(uri, routingContext);

			// must lookup domain else lookup by url fails
			var builder = new PublishedContentRequestBuilder(docreq);
			builder.LookupDomain();
			Assert.AreEqual(expectedCulture, docreq.Culture.Name);

			var lookup = new LookupByNiceUrl();
			var result = lookup.TrySetDocument(docreq);
			Assert.IsTrue(result);
			Assert.AreEqual(expectedId, docreq.DocumentId);
		}
		public void Lookup_SingleDomain(string url, int expectedId)
		{
			SetDomains3();

			ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");

			var routingContext = GetRoutingContext(url);
			var uri = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
			var docreq = new PublishedContentRequest(uri, routingContext);

			// must lookup domain else lookup by url fails
			var builder = new PublishedContentRequestBuilder(docreq);
			builder.LookupDomain();

			var lookup = new LookupByNiceUrl();
			var result = lookup.TrySetDocument(docreq);
			Assert.IsTrue(result);
			Assert.AreEqual(expectedId, docreq.DocumentId);
		}