/// <summary> /// This will record a 404 error or /// </summary> /// <param name="context"></param> /// <returns></returns> public bool Handle404(HttpContext context) { string strWebSiteDomain = WebTools.GetWebSiteURL(); string strPage = context.Request.Url.ToString(); string strOriginalRequestedPage; #region Strip Domain Name if (strPage.Contains("404;")) { strPage = General.StringFunctions.AllAfter(strPage, "404;"); } if (strPage.Contains(":80/")) { strPage = General.StringFunctions.AllAfter(strPage, ":80/"); } if (strPage.Contains(":443/")) { strPage = General.StringFunctions.AllAfter(strPage, ":443/"); } strPage = strPage.Replace("404.aspx?", ""); strPage = strPage.Replace(strWebSiteDomain + ":80/", ""); strPage = strPage.Replace(strWebSiteDomain + ":443/", ""); strPage = strPage.Replace(strWebSiteDomain + ":443/", ""); strPage = strPage.Replace(strWebSiteDomain + "/", ""); strPage = strPage.Replace(strWebSiteDomain.Replace("www.", "") + ":80/", ""); strPage = strPage.Replace(strWebSiteDomain.Replace("www.", "") + ":443/", ""); strPage = strPage.Replace(strWebSiteDomain.Replace("www.", "") + "/", ""); strPage = strPage.Replace(strWebSiteDomain.Replace("www.", "beta.") + "/", ""); strPage = strPage.Replace(strWebSiteDomain.Replace("www.", "beta1.") + "/", ""); strPage = strPage.Replace(strWebSiteDomain.Replace("www.", "beta2.") + "/", ""); strPage = strPage.Replace(strWebSiteDomain.Replace("www.", "beta3.") + "/", ""); strPage = strPage.Replace("aspxerrorpath=/", ""); strPage = rgxLocalHost.Replace(strPage, ""); #endregion strOriginalRequestedPage = strPage; string strQuery = WebTools.GetQueryString(strPage); //Store Query String strPage = WebTools.RemoveQueryString(strPage); //Remove Query String #region Remove All After # if (strPage.Contains("#")) { string[] astrUrl = strPage.Split('#'); strPage = astrUrl[0]; } #endregion #region Forward to Toolkit CMS Redirects rechecklist : List <Error404Redirect> lstPageRedirects = PageRedirects; if (lstPageRedirects != null) { var objRedirPage = lstPageRedirects.Where(page => PageMatch(page.From, strPage) == true).FirstOrDefault(); if (objRedirPage != null) { objRedirPage.RecordUse(); if (objRedirPage.From.EndsWith("*")) { if (objRedirPage.To.EndsWith("*")) { string strNewPage = objRedirPage.To.Replace("*", Regex.Replace(strPage, objRedirPage.From.TrimEnd('*').TrimStart('/'), "", RegexOptions.IgnoreCase)); Forward(context, strNewPage, strQuery, objRedirPage.RedirectType); } else { Forward(context, objRedirPage.To, strQuery, objRedirPage.RedirectType); } } else { Forward(context, objRedirPage.To, strQuery, objRedirPage.RedirectType); } return(true); //True because the request was redirected } else if (!RedirectPagesAlreadyDBDoubleChecked.Contains(strPage)) { if (General.ErrorLogging.Data.Error404Redirect.GetError404Redirect(AppID, ClientID, strPage) != null) { ReloadPageRedirects(); //Save and Reload the data goto rechecklist; } else { RedirectPagesAlreadyDBDoubleChecked.Add(strPage); } } } #endregion #region Default Handling / Hard Coded Redirects switch (System.IO.Path.GetExtension(strPage)) { case ".html": //HTML case ".htm": case ".xhtml": case ".jhtml": case ".aspx": //ASP case ".asp": case ".rb": //Ruby case ".rhtml": case ".php": //PHP case ".phtml": case ".php4": case ".php3": case ".shtml": case ".cfm": //Coldfusion case ".jsp": //Java case ".jspx": case ".do": case ".action": case ".wss": case ".pl": //Perl case ".py": //Python case ".cgi": //Other case ".dll": case "": break; default: #region Otherwise Report the 404 Error and let the 404 Page display Report404(context, strOriginalRequestedPage, strQuery); context.Server.ClearError(); return(false); #endregion } #region Remove File Extension string strPageWithExtention = strPage; strPage = strPage.Replace(".aspx", ""); strPage = strPage.Replace(".html", ""); strPage = strPage.Replace(".htm", ""); strPage = strPage.Replace(".xhtml", ""); strPage = strPage.Replace(".jhtml", ""); strPage = strPage.Replace(".rhtml", ""); strPage = strPage.Replace(".rb", ""); strPage = strPage.Replace(".php", ""); strPage = strPage.Replace(".shtml", ""); strPage = strPage.Replace(".asp", ""); strPage = strPage.Replace(".cfm", ""); strPage = strPage.Replace(".pl", ""); strPage = strPage.Replace(".jsp", ""); strPage = strPage.Replace(".jspx", ""); strPage = strPage.Replace(".ws", ""); strPage = strPage.Replace(".action", ""); strPage = strPage.Replace(".cgi", ""); strPage = strPage.Replace(".dll", ""); #endregion #region Forward to Hard Coded Redirects switch (strPage.ToLower()) { case "default": case "index": Forward(context, "/"); return(true); default: Report404(context, strOriginalRequestedPage, strQuery); context.Server.ClearError(); break; } #endregion #endregion return(false); //False because the request was not redirected }