void parser_PageNotFound(object sender, PageNotFoundEventArgs e) { Url url = e.Url; var segments = url.Path.Trim('~', '/').Split('/'); var applicationSegments = Url.ApplicationPath.Count(c => c == '/'); for (int i = segments.Length; i >= applicationSegments; i--) { var partialUrl = "/" + string.Join("/", segments, 0, i); foreach (var item in repository.Find(Parameter.Like("DirectUrl", partialUrl).Detail().Take(host.Sites.Count + 1))) { if (i >= segments.Length) { // direct hit if (TryApplyFoundItem(url, e, item)) { return; } } else { // try to find subpath var remainder = string.Join("/", segments, i, segments.Length - applicationSegments); var child = item.GetChild(remainder); if (child != null) { if (TryApplyFoundItem(url, e, child)) { return; } } } } } }
void parser_PageNotFound(object sender, PageNotFoundEventArgs e) { Url url = e.Url; var segments = url.Path.Trim('~', '/').Split('/'); var applicationSegments = Url.ApplicationPath.Count(c => c == '/'); for (int i = segments.Length; i >= applicationSegments; i--) { var partialUrl = "/" + string.Join("/", segments, 0, i); foreach (var item in repository.Find((Parameter.Like("DirectUrl", partialUrl).Detail() & Parameter.Equal("State", ContentState.Published)).Take(host.Sites.Count + 1))) { if (i >= segments.Length) { // direct hit if (TryApplyFoundItem(url, e, item)) return; } else { // try to find subpath var remainder = string.Join("/", segments, i, segments.Length - applicationSegments); var child = item.GetChild(remainder); if (child != null) { if (TryApplyFoundItem(url, e, child)) return; } } } } }
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)); }
void parser_PageNotFound(object sender, PageNotFoundEventArgs e) { StartPage startPage = parser.StartPage as StartPage; if (startPage != null && startPage.NotFoundPage != null && !e.Url.StartsWith("edit/", StringComparison.InvariantCultureIgnoreCase)) { e.AffectedItem = startPage.NotFoundPage; } }
private bool TryApplyFoundItem(Url url, PageNotFoundEventArgs e, ContentItem item) { if (!string.IsNullOrEmpty(url.Authority)) { var site = host.GetSite(item); if (!string.IsNullOrEmpty(site.Authority) && !site.Is(url.Authority)) return false; } e.AffectedItem = item; if (e.AffectedPath != null) e.AffectedPath.CurrentItem = item; return true; }
/// <summary>Returns a page when no page is found. This method will return the start page if the url matches the default content page property.</summary> /// <param name="url"></param> /// <returns></returns> protected virtual ContentItem NotFoundPage(string url) { if (IsDefaultDocument(url)) { return(StartPage); } logger.Debug("No content at: " + url); PageNotFoundEventArgs args = new PageNotFoundEventArgs(url); if (PageNotFound != null) { PageNotFound(this, args); } return(args.AffectedItem); }
private bool TryApplyFoundItem(Url url, PageNotFoundEventArgs e, ContentItem item) { if (!string.IsNullOrEmpty(url.Authority)) { var site = host.GetSite(item); if (!string.IsNullOrEmpty(site.Authority) && !site.Is(url.Authority)) { return(false); } } e.AffectedItem = item; if (e.AffectedPath != null) { e.AffectedPath.CurrentItem = item; } return(true); }
private bool TryApplyFoundItem(Url url, PageNotFoundEventArgs e, ContentItem item) { var currentSite = host.CurrentSite; //get site by host in current url; if not found it returns DefaultSite var itemSite = host.GetSite(item); //get site by the item found with path in current url //if itemSite is null then we would try getting site by url but that would be the same as current site above so in that case we just consider match success and fall through. if (itemSite != null && currentSite.StartPageID != itemSite.StartPageID) { return(false); } e.AffectedItem = item; if (e.AffectedPath != null) { e.AffectedPath.CurrentItem = item; } return(true); }
public void InvokePageNotFound(PageNotFoundEventArgs e) { PageNotFound(this, e); }
/// <summary>Returns a page when no page is found. This method will return the start page if the url matches the default content page property.</summary> /// <param name="url"></param> /// <returns></returns> protected virtual ContentItem NotFoundPage(string url) { if (IsDefaultDocument(url)) { return StartPage; } Debug.WriteLine("No content at: " + url); PageNotFoundEventArgs args = new PageNotFoundEventArgs(url); if (PageNotFound != null) PageNotFound(this, args); return args.AffectedItem; }
public PathData ResolvePath(Url url) { 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.PhysicalPath); return UseItemIfAvailable(item, data); }