예제 #1
0
 public void CanConstruct_FromHostName()
 {
     Url u = new Url("http://somesite/");
     Assert.That(u.Scheme, Is.EqualTo("http"));
     Assert.That(u.Authority, Is.EqualTo("somesite"));
     Assert.That(u.ToString(), Is.EqualTo("http://somesite/"));
 }
예제 #2
0
 public void CanConstruct_AbsoluteLocalPath_WithQuery()
 {
     Url u = new Url("/hello.aspx?something=someotherthing");
     Assert.That(u.Path, Is.EqualTo("/hello.aspx"));
     Assert.That(u.Query, Is.EqualTo("something=someotherthing"));
     Assert.That(u.ToString(), Is.EqualTo("/hello.aspx?something=someotherthing"));
 }
예제 #3
0
 public void CanConstruct_AbsoluteLocalPath_WithFragment()
 {
     Url u = new Url("/hello.aspx#somebookmark");
     Assert.That(u.Path, Is.EqualTo("/hello.aspx"));
     Assert.That(u.Fragment, Is.EqualTo("somebookmark"));
     Assert.That(u.ToString(), Is.EqualTo("/hello.aspx#somebookmark"));
 }
예제 #4
0
		public FakeHttpContext(Url url)
			: this()
		{
			request.appRelativeCurrentExecutionFilePath = "~" + url.Path;
			foreach (var q in url.GetQueries())
				request.query[q.Key] = q.Value;
			request.rawUrl = url.PathAndQuery;
		}
예제 #5
0
        public FakeHttpContext(Url url)
            : this()
        {
            request.appRelativeCurrentExecutionFilePath = "~" + url.Path;
            foreach (var q in url.GetQueries())
                request.query[q.Key] = q.Value;
            request.rawUrl = url.PathAndQuery;
			if (url.Path.IndexOf(".ashx/") > 0)
				request.pathInfo = url.Path.Substring(url.Path.IndexOf(".ashx/") + 5);
        }
        public virtual void CreateSize(Url virtualPath, byte[] image, ImageSizeElement size)
        {
            if (!size.ResizeOnUpload)
                return;

            string resizedPath = ImagesUtility.GetResizedPath(virtualPath, size.Name);

			using (var sourceStream = new MemoryStream(image))
			{
				if (size.Width <= 0 && size.Height <= 0)
				{
					using (var destinationStream = files.OpenFile(resizedPath))
					{
						int b;
						while ((b = sourceStream.ReadByte()) != -1)
						{
							destinationStream.WriteByte((byte)b);
						}
					}
				}
				else
				{
					// Delete the image before writing.
					// Fixes a weird bug where overwriting the original file while it still exists
					//  leaves the resized image the with the exact same file size as the original even 
					//  though it should be smaller.
					if (files.FileExists(resizedPath))
					{
						files.DeleteFile(resizedPath);
					}

					try
					{
						using (var destinationStream = files.OpenFile(resizedPath))
						{
							resizer.Resize(sourceStream, new ImageResizeParameters(size.Width, size.Height, size.Mode) { Quality = size.Quality }, destinationStream);
						}
					}
					catch
					{
					}
				}
			}
		}
예제 #7
0
 public void CanConstruct_AbsoluteLocalPath()
 {
     Url u = new Url("/hello.aspx");
     Assert.That(u.Path, Is.EqualTo("/hello.aspx"));
     Assert.That(u.ToString(), Is.EqualTo("/hello.aspx"));
 }
예제 #8
0
		public void NullUrl()
		{
			Url u = new Url((string)null);
			Assert.That(u.Path, Is.EqualTo(""));
			Assert.That(u.ToString(), Is.EqualTo(""));
		}
예제 #9
0
 private string CleanUrl(string url)
 {
     url = Url.PathPart(url);
     url = Url.ToRelative(url);
     return(url.TrimStart('~', '/'));
 }
예제 #10
0
		public void CanConstruct_WithBaseSchemeAndRawUrl()
		{
			Url u = new Url("http", "www.n2cms.com", "/Default.aspx?");
			Assert.That(u.Scheme, Is.EqualTo("http"));
			Assert.That(u.Authority, Is.EqualTo("www.n2cms.com"));
			Assert.That(u.PathAndQuery, Is.EqualTo("/Default.aspx"));
		}
예제 #11
0
        public void UpdatingQueryToNull_ReturnsOtherParameters_WhenUpdatingLast()
        {
            Url u = new Url("/hello.aspx?something=someotherthing&query=value&query3=value3");
            u = u.SetQueryParameter("query3", null);
            Assert.That(u.ToString(), Is.EqualTo("/hello.aspx?something=someotherthing&query=value"));
		}
예제 #12
0
 public void Getting_Query_WhenNoQueries_GivesNull()
 {
     Url u = new Url("/hello.aspx");
     var q = u.GetQuery("something");
     Assert.That(q, Is.Null);
 }
예제 #13
0
파일: Link.cs 프로젝트: spmason/n2cms
 public ILinkBuilder AddQuery(string key, string value)
 {
     url = url.SetQueryParameter(key, value);
     return this;
 }
예제 #14
0
 public void CanGet_QueryDictionary()
 {
     Url u = new Url("/hello.aspx?something=someotherthing");
     var q = u.GetQueries();
     Assert.That(q.Count, Is.EqualTo(1));
     Assert.That(q["something"], Is.EqualTo("someotherthing"));
 }
		void securityEnforcer_AuthorizationFailed(object sender, CancellableItemEventArgs e)
		{
			var url = new Url("{ManagementUrl}/Login.aspx").ResolveTokens();
			url.AppendQuery("returnUrl", _context.Url.LocalUrl);
			_context.HttpContext.Response.Redirect(url);
		}
예제 #16
0
        protected RouteData RequestingUrl(Url url)
        {
            httpContext.request.appRelativeCurrentExecutionFilePath = "~" + url.Path;
            httpContext.request.rawUrl = url;

            NameValueCollection nvc = new NameValueCollection();
            foreach (var kvp in url.GetQueries())
                nvc[kvp.Key] = kvp.Value;
            httpContext.request.query = nvc;

            foreach (var kvp in url.GetQueries())
                httpContext.request.query[kvp.Key] = kvp.Value;

            var data = route.GetRouteData(httpContext);
            requestContext = new RequestContext(httpContext, data);
            urlHelper = new UrlHelper(requestContext, routes);
            htmlHelper = new HtmlHelper(new ViewContext { RequestContext = requestContext, HttpContext = httpContext, RouteData = requestContext.RouteData, Writer = httpContext.Response.Output }, new ViewPage(), routes);
            return data;
        }
예제 #17
0
 public void CanGet_NameVAlueCollection()
 {
     Url u = new Url("/hello.aspx?something=someotherthing");
     var q = u.GetQueryNameValues()["something"];
     Assert.That(q, Is.EqualTo("someotherthing"));
 }
예제 #18
0
파일: Link.cs 프로젝트: spmason/n2cms
 public ILinkBuilder Query(string query)
 {
     url = url.SetQuery(query);
     return this;
 }
예제 #19
0
        /// <summary>Calculates an item url by walking it's parent path.</summary>
        /// <param name="item">The item whose url to compute.</param>
        /// <returns>A friendly url to the supplied item.</returns>
        public virtual string BuildUrl(ContentItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            ContentItem current = item;

            if (item.VersionOf != null)
            {
                current = item.VersionOf;
            }

            // move up until first real page
            while (current != null && !current.IsPage)
            {
                current = current.Parent;
            }

            // no page found, use rewritten url
            if (current == null)
            {
                throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item);
            }

            Url url;

            if (host.IsStartPage(current))
            {
                // we move right up to the start page
                url = "/";
            }
            else
            {
                // at least one node before the start page
                url     = new Url("/" + current.Name + current.Extension);
                current = current.Parent;
                // build path until a start page
                while (current != null && !host.IsStartPage(current))
                {
                    url     = url.PrependSegment(current.Name);
                    current = current.Parent;
                }
            }

            // no start page found, use rewritten url
            if (current == null)
            {
                return(item.FindPath(PathData.DefaultAction).RewrittenUrl);
            }

            if (item.IsPage && item.VersionOf != null)
            {
                // the item was a version, add this information as a query string
                url = url.AppendQuery(PathData.PageQueryKey, item.ID);
            }
            else if (!item.IsPage)
            {
                // the item was not a page, add this information as a query string
                url = url.AppendQuery(PathData.ItemQueryKey, item.ID);
            }

            return(Url.ToAbsolute("~" + url));
        }
예제 #20
0
 public void CanGet_Query()
 {
     Url u = new Url("/hello.aspx?something=someotherthing");
     var q = u.GetQuery("something");
     Assert.That(q, Is.EqualTo("someotherthing"));
 }
예제 #21
0
 public ActionResult ChangeAccount()
 {
     N2.Web.Url url = CurrentPage.Url;
     return(Redirect(url.AppendQuery("changeaccount", CurrentItem.ID)));
 }
예제 #22
0
 public ILinkBuilder SetFragment(string fragment)
 {
     this.url = url.SetFragment(fragment);
     return this;
 }
예제 #23
0
 public void CanSplitPath_IntoPathWithoutExtension()
 {
     Url u = new Url("/hello.aspx?something=someotherthing");
     Assert.That(u.PathWithoutExtension, Is.EqualTo("/hello"));
 }
예제 #24
0
 public ActionResult Reconfigure()
 {
     N2.Web.Url url = CurrentPage.Url;
     return(Redirect(url.AppendQuery("reconfigure", CurrentItem.ID)));
 }
예제 #25
0
 public void CanGet_EmptyQueryDictionary()
 {
     Url u = new Url("/hello.aspx");
     var q = u.GetQueries();
     Assert.That(q.Count, Is.EqualTo(0));
 }
예제 #26
0
 private ActionResult RedirectToIndex(string errorText)
 {
     N2.Web.Url url = CurrentPage.Url;
     return(Redirect(url.AppendQuery("failure", CurrentItem.ID).AppendQuery("errorText", errorText)));
 }
예제 #27
0
 public void Getting_NonExistantQuery_GivesNull()
 {
     Url u = new Url("/hello.aspx?something=someotherthing");
     var q = u.GetQuery("nothing");
     Assert.That(q, Is.Null);
 }
예제 #28
0
		public string SelectedUrl(Url baseUrl, ContentItem selected = null)
		{
			return baseUrl.AppendQuery(SelectedQueryKey, (selected ?? SelectedItem).Path).ResolveTokens();
		}
예제 #29
0
 public void UpdatingQueryToNull_WhenSingleParameter_RemovesItFromUrl()
 {
     Url u = new Url("/hello.aspx?something=someotherthing");
     u = u.SetQueryParameter("something", null);
     Assert.That(u.ToString(), Is.EqualTo("/hello.aspx"));
 }
예제 #30
0
 public void CanConstruct_HomePath()
 {
     Url u = new Url("/");
     Assert.That(u.Path, Is.EqualTo("/"));
     Assert.That(u.ToString(), Is.EqualTo("/"));
 }
예제 #31
0
		public void CanClearExtension()
		{
			Url u = new Url("/hello.aspx?something=someotherthing");
			u = u.SetExtension("");
			Assert.That(u.ToString(), Is.EqualTo("/hello?something=someotherthing"));
		}
예제 #32
0
 public void CanConstruct_FromHostName_WithPath_AndQuery_AndFragment()
 {
     Url u = new Url("http://somesite/some/path?key=value#bookmark");
     Assert.That(u.Scheme, Is.EqualTo("http"));
     Assert.That(u.Authority, Is.EqualTo("somesite"));
     Assert.That(u.Path, Is.EqualTo("/some/path"));
     Assert.That(u.Query, Is.EqualTo("key=value"));
     Assert.That(u.Fragment, Is.EqualTo("bookmark"));
     Assert.That(u.ToString(), Is.EqualTo("http://somesite/some/path?key=value#bookmark"));
 }
예제 #33
0
        public void EmptyUrl()
        {
            Url u = new Url("");
            Assert.That(u.Path, Is.EqualTo(""));
            Assert.That(u.ToString(), Is.EqualTo(""));
		}
예제 #34
0
 /// <summary>May be overridden to provide custom start page depending on authority.</summary>
 /// <param name="url">The host name and path information.</param>
 /// <returns>The configured start page.</returns>
 protected virtual ContentItem GetStartPage(Url url)
 {
     return(StartPage);
 }