public void Process(HttpProcessingContext context) { var customRedirects = CustomRedirectCache.From(context.NhSession) .CustomRedirects .Where(x => x.IsEnabled) .OrderByDescending(x => x.Priority) .ThenBy(x => x.Id); foreach (var customRedirect in customRedirects) { string destinationUrl; if (TryMatch(context, customRedirect, out destinationUrl)) { context.Redirection = new HttpRedirection { RedirectMode = customRedirect.RedirectMode, RedirectUrl = destinationUrl }; context.StopProcessing = true; break; } } }
private bool TryMatch(HttpProcessingContext context, CustomRedirect redirect, out string destinationUrl) { var originalUrl = context.Request.Url.ToString(); destinationUrl = null; if (redirect.MatchByRegex) { if (Regex.IsMatch(originalUrl, redirect.From, RegexOptions.IgnoreCase)) { destinationUrl = Regex.Replace(originalUrl, redirect.From, redirect.To, RegexOptions.IgnoreCase); return true; } } else { if (redirect.From.StartsWith("/")) { originalUrl = context.Request.Url.PathAndQuery; } if (originalUrl.Equals(redirect.From, StringComparison.OrdinalIgnoreCase)) { destinationUrl = redirect.To; return true; } } return false; }
private void context_BeginRequest(object sender, EventArgs e) { var context = new HttpProcessingContext(new HttpContextWrapper(HttpContext.Current).Request, Database.GetCurrentSession()); HttpProcessors.Process(context); if (context.Redirection != null && !String.IsNullOrEmpty(context.Redirection.RedirectUrl)) { if (context.Redirection.RedirectMode == RedirectMode.Temporary) { context.Response.Redirect(context.Redirection.RedirectUrl, true); } else { context.Response.RedirectPermanent(context.Redirection.RedirectUrl, true); } } else if (context.MatchedPage != null) { var page = context.MatchedPage; var suffix = String.Join("/", context.RemainingSegments); if (!String.IsNullOrEmpty(suffix)) { suffix = HttpUtility.UrlEncode(suffix); } var url = String.Format("{0}?{1}={2}&suffix={3}{4}", page.Layout.AspxVirtualPath, LayoutPageBase.QueryStringParam_PageId, page.Id, suffix, SerializeQueryString(context.Request.QueryString)); context.HttpContext.RewritePath(url); } }
public static void Process(HttpProcessingContext context) { foreach (var processor in Processors) { processor.Process(context); if (context.StopProcessing) break; } }
public void Process(HttpProcessingContext context) { var domain = context.Request.Url.Host; var bindedPage = PageCache.From(context.NhSession).FindPageByDomain(domain); if (bindedPage != null) { context.MatchedPage = bindedPage; } }
public void Process(HttpProcessingContext context) { var frontendSettings = GlobalSettingManager.Instance.FrontendSettings; if (!frontendSettings.Multilingual) return; var languages = FrontendLanguageCache.From(context.NhSession); // Check lanuage by domain var language = languages.FindByDomain(context.Request.Url.Host); // check lanage by first url segment if (language == null && context.RemainingSegments.Count > 0) { var cultureName = context.RemainingSegments[0]; language = languages.FindByName(cultureName); if (language != null) { context.RemainingSegments.RemoveAt(0); } } // Check user browser's language if (language == null && context.Request.UserLanguages != null && context.Request.UserLanguages.Length > 0) { foreach (var name in context.Request.UserLanguages) { language = languages.FindByName(name); if (language != null) { break; } } } // use default language if (language == null) { language = languages.Languages.FirstOrDefault(); } if (language != null) { context.Culture = CultureInfo.GetCultureInfo(language.Name); } System.Threading.Thread.CurrentThread.CurrentCulture = context.Culture; System.Threading.Thread.CurrentThread.CurrentUICulture = context.Culture; }
public void Process(HttpProcessingContext context) { if (context.RemainingSegments.Count > 0 && context.RemainingSegments[0].Equals("default.aspx", StringComparison.OrdinalIgnoreCase)) { return; } if (context.RemainingSegments.Count > 0 && _ignoredFolders.Contains(context.RemainingSegments[0])) { context.StopProcessing = true; return; } if (!String.IsNullOrEmpty(context.FileExtension) && _ignoredExtensions.Contains(context.FileExtension)) { context.StopProcessing = true; return; } }
public void Process(HttpProcessingContext context) { if (context.RemainingSegments.Count == 0) { return; } var match = _regex.Match(context.RemainingSegments[context.RemainingSegments.Count - 1]); if (match.Success) { var rewritePath = "~/Plugins/Seeger.Plugins.Seo/Sitemap.ashx"; var idGroup = match.Groups["id"]; if (idGroup.Success) { rewritePath += "?sitemapId=" + idGroup.Value; } context.HttpContext.RewritePath(rewritePath); context.StopProcessing = true; } }
public void Process(HttpProcessingContext context) { if (context.MatchedPage != null) return; if (context.RemainingSegments.Count == 0 || context.RemainingSegments[0].Equals("default.aspx", StringComparison.OrdinalIgnoreCase)) { var pageCache = PageCache.From(context.NhSession); if (pageCache.Homepage != null && pageCache.Homepage.Published) { context.MatchedPage = pageCache.Homepage; context.StopProcessing = true; if (context.RemainingSegments.Count > 0) { context.RemainingSegments.RemoveAt(0); } return; } throw new HttpException(404, "Page Not Found."); } }
public void Process(HttpProcessingContext context) { if (context.RemainingSegments.Count == 0) return; var checkUnpublished = false; Boolean.TryParse(context.Request.QueryString["showUnpublished"], out checkUnpublished); var segments = context.RemainingSegments.ToList(); PageItem matchedPage = null; IEnumerable<PageItem> candidates = null; if (context.MatchedPage == null) { candidates = PageCache.From(context.NhSession).RootPages; } else { candidates = context.MatchedPage.Pages; } for (var i = 0; i < segments.Count; i++) { var matched = false; foreach (var candidate in candidates) { if (candidate.UrlSegment.Equals(segments[i], StringComparison.OrdinalIgnoreCase)) { matchedPage = candidate; candidates = candidate.Pages; context.RemainingSegments.RemoveAt(0); matched = true; break; } } if (!matched) { break; } } if (matchedPage != null) { context.MatchedPage = matchedPage; } if (context.MatchedPage != null) { // if RemainingSegments.Count > 0, it means this is not an exact match, // then we need to check if this is a directly file request. // Example: Cms page /home/products is binded to xxx.com using page domain binding. // When a visitor visits website using xxx.com, page '/home/products' will always be matched. // So if the visitor visits xxx.com/file.psd, we need to first check if file.psd exists in the file system. // Otherwise the visitor will see homepage even when he is requesting file.psd if (context.RemainingSegments.Count > 0 && File.Exists(HostingEnvironment.MapPath(context.Request.Path))) { context.MatchedPage = null; } } }