private void Context_EndRequest(object sender, EventArgs e) { if (IsUpgrade) { return; } try { var rsp = HttpContext.Current.Response; var ps = Common.CurrentPortalSettings; // this needs to be done on EndRequest, to be sure PortalSettings.ActiveTab is correct if (rsp.StatusCode == (int)HttpStatusCode.OK) { Force404Controller.DoForce404Check(); } string incoming = Common.IncomingUrl; if (ps.ActiveTab?.TabID != ps.ErrorPage404 && rsp.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(incoming)) { Common.Logger.Debug($"Logging redirect from Context_EndRequest. incoming:[{incoming}]"); RedirectController.AddRedirectLog(ps.PortalId, incoming, ""); } } catch (Exception exception) { // we're not writing in the eventlog, since the amount of log records can really explode // we MUST catch every possible exception here, otherwise the website would be completely down in case of a bug } }
public static void DoForce404Check() { // no forced 404 for authenticated users if (HttpContext.Current.Request.IsAuthenticated) { return; } // als tabInfo.IsForce404() en de url is "dieper" dan de tab zelf: dan een 404 geven var activeTab = Common.CurrentPortalSettings.ActiveTab; if (activeTab.IsForce404() && !IsDnnControlUrl()) { Common.Logger.Debug($"Force404-check for tab {Common.CurrentPortalSettings.ActiveTab.TabID}"); var tabFullUrl = ""; // activeTab can be a tab when handlers are being called. // in those cases, FullUrl throws an exception // we're "handling" that here try { tabFullUrl = activeTab.FullUrl.ToLowerInvariant(); } catch (Exception e) { } if (string.IsNullOrEmpty(tabFullUrl)) { return; } var incoming = Common.IncomingUrl; var tabUrl = new Uri(tabFullUrl); var incUrl = new Uri(incoming); // requests for dependancyhandler.axd don't get recognised as a handler and need to be explicitly ignored if (incoming.Contains("dependencyhandler.axd")) { return; } if (incUrl.LocalPath.StartsWith(tabUrl.LocalPath) && incUrl.LocalPath.Length > tabUrl.LocalPath.Length) { RedirectController.AddRedirectLog(Common.CurrentPortalSettings.PortalId, incoming, ""); Common.Handle404Exception(HttpContext.Current.Response, Common.CurrentPortalSettings); } // also check TabUrls with httpstatus=200 foreach (var tabUrlInfo in activeTab.TabUrls.Where(tu => tu.HttpStatus == ((int)HttpStatusCode.OK).ToString())) { if (incUrl.LocalPath.StartsWith(tabUrlInfo.Url.ToLowerInvariant()) && incUrl.LocalPath.Length > tabUrlInfo.Url.Length) { RedirectController.AddRedirectLog(Common.CurrentPortalSettings.PortalId, incoming, ""); Common.Handle404Exception(HttpContext.Current.Response, Common.CurrentPortalSettings); } } } }
private void Context_EndRequest(object sender, EventArgs e) { try { var rsp = HttpContext.Current.Response; var ps = Common.CurrentPortalSettings; string incoming = (string)HttpContext.Current.Items["40F_SEO_IncomingUrl"]; if (rsp.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(incoming)) { Common.Logger.Debug($"Logging redirect from Context_EndRequest. incoming:[{incoming}]"); RedirectController.AddRedirectLog(ps.PortalId, incoming, ""); } } catch (Exception exception) { // we're not writing in the eventlog, since the amount of log records can really explode // we MUST catch every possible exception here, otherwise the website would be completely down in case of a bug } }