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/")); }
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")); }
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")); }
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; }
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 { } } } }
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")); }
public void NullUrl() { Url u = new Url((string)null); Assert.That(u.Path, Is.EqualTo("")); Assert.That(u.ToString(), Is.EqualTo("")); }
private string CleanUrl(string url) { url = Url.PathPart(url); url = Url.ToRelative(url); return(url.TrimStart('~', '/')); }
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")); }
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")); }
public void Getting_Query_WhenNoQueries_GivesNull() { Url u = new Url("/hello.aspx"); var q = u.GetQuery("something"); Assert.That(q, Is.Null); }
public ILinkBuilder AddQuery(string key, string value) { url = url.SetQueryParameter(key, value); return this; }
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); }
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; }
public void CanGet_NameVAlueCollection() { Url u = new Url("/hello.aspx?something=someotherthing"); var q = u.GetQueryNameValues()["something"]; Assert.That(q, Is.EqualTo("someotherthing")); }
public ILinkBuilder Query(string query) { url = url.SetQuery(query); return this; }
/// <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)); }
public void CanGet_Query() { Url u = new Url("/hello.aspx?something=someotherthing"); var q = u.GetQuery("something"); Assert.That(q, Is.EqualTo("someotherthing")); }
public ActionResult ChangeAccount() { N2.Web.Url url = CurrentPage.Url; return(Redirect(url.AppendQuery("changeaccount", CurrentItem.ID))); }
public ILinkBuilder SetFragment(string fragment) { this.url = url.SetFragment(fragment); return this; }
public void CanSplitPath_IntoPathWithoutExtension() { Url u = new Url("/hello.aspx?something=someotherthing"); Assert.That(u.PathWithoutExtension, Is.EqualTo("/hello")); }
public ActionResult Reconfigure() { N2.Web.Url url = CurrentPage.Url; return(Redirect(url.AppendQuery("reconfigure", CurrentItem.ID))); }
public void CanGet_EmptyQueryDictionary() { Url u = new Url("/hello.aspx"); var q = u.GetQueries(); Assert.That(q.Count, Is.EqualTo(0)); }
private ActionResult RedirectToIndex(string errorText) { N2.Web.Url url = CurrentPage.Url; return(Redirect(url.AppendQuery("failure", CurrentItem.ID).AppendQuery("errorText", errorText))); }
public void Getting_NonExistantQuery_GivesNull() { Url u = new Url("/hello.aspx?something=someotherthing"); var q = u.GetQuery("nothing"); Assert.That(q, Is.Null); }
public string SelectedUrl(Url baseUrl, ContentItem selected = null) { return baseUrl.AppendQuery(SelectedQueryKey, (selected ?? SelectedItem).Path).ResolveTokens(); }
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")); }
public void CanConstruct_HomePath() { Url u = new Url("/"); Assert.That(u.Path, Is.EqualTo("/")); Assert.That(u.ToString(), Is.EqualTo("/")); }
public void CanClearExtension() { Url u = new Url("/hello.aspx?something=someotherthing"); u = u.SetExtension(""); Assert.That(u.ToString(), Is.EqualTo("/hello?something=someotherthing")); }
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")); }
public void EmptyUrl() { Url u = new Url(""); Assert.That(u.Path, Is.EqualTo("")); Assert.That(u.ToString(), Is.EqualTo("")); }
/// <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); }