public PathData ResolvePath(Url url) { if (url == null) { return(PathData.Empty); } Url requestedUrl = url; ContentItem item = TryLoadingFromQueryString(requestedUrl, PathData.ItemQueryKey); ContentItem page = TryLoadingFromQueryString(requestedUrl, PathData.PageQueryKey); if (page != null) { var directPath = page.FindPath(requestedUrl["action"] ?? PathData.DefaultAction) .SetArguments(requestedUrl["arguments"]) .UpdateParameters(requestedUrl.GetQueries()); var directData = UseItemIfAvailable(item, directPath); // check whether to rewrite requests with page in query string since this might be already rewritten directData.IsRewritable &= !string.Equals(url.ApplicationRelativePath, directData.TemplateUrl, StringComparison.InvariantCultureIgnoreCase); return(directData); } ContentItem startPage = GetStartPage(requestedUrl); if (startPage == null) { return(PathData.Empty); } string path = Url.ToRelative(requestedUrl.Path).TrimStart('~'); PathData data = startPage.FindPath(path).UpdateParameters(requestedUrl.GetQueries()); if (data.IsEmpty()) { if (path.EndsWith(DefaultDocument, StringComparison.OrdinalIgnoreCase)) { // Try to find path without default document. data = StartPage .FindPath(StripDefaultDocument(path)) .UpdateParameters(requestedUrl.GetQueries()); } if (data.IsEmpty()) { // Allow user code to set path through event if (PageNotFound != null) { PageNotFoundEventArgs args = new PageNotFoundEventArgs(requestedUrl); args.AffectedPath = data; PageNotFound(this, args); data = args.AffectedPath; } } } data.Ignore = !IgnoreExisting(webContext.HttpContext.Request.PhysicalPath); return(UseItemIfAvailable(item, data)); }
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 void CanGet_EmptyQueryDictionary() { Url u = new Url("/hello.aspx"); var q = u.GetQueries(); Assert.That(q.Count, Is.EqualTo(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")); }
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; }