/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { try { // Set form action to pass XSS test form1.Action = "/"; // try to get site's 404 page var host = WebRequestHelper.GetHostNameFromRequest(HttpContext.Current); SiteCache site = SiteCache.GetSiteByDomain(host); if (site != null && site.PageNotFoundPageId.HasValue) { site.RedirectToPageNotFoundPage(); } else { Response.StatusCode = 404; lLogoSvg.Text = System.IO.File.ReadAllText(HttpContext.Current.Request.MapPath("~/Assets/Images/rock-logo-sm.svg")); } } catch { Response.StatusCode = 404; lLogoSvg.Text = System.IO.File.ReadAllText(HttpContext.Current.Request.MapPath("~/Assets/Images/rock-logo-sm.svg")); } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { try { // Set form action to pass XSS test form1.Action = "/"; // try to get site's 404 page SiteCache site = SiteCache.GetSiteByDomain(Request.Url.Host); if (site != null && site.PageNotFoundPageId.HasValue) { site.RedirectToPageNotFoundPage(); } else { Response.StatusCode = 404; lLogoSvg.Text = System.IO.File.ReadAllText(HttpContext.Current.Request.MapPath("~/Assets/Images/rock-logo-sm.svg")); // Jeremy Weatherford [email protected] // use BRShortLinks table to redirect to a matching Url // see BRShortLinks.aspx.cs for where they come from string search = Request.RawUrl.ToLower(); int idx = search.IndexOf("?"); if (idx != -1) { search = search.Substring(0, idx); // stop at ? } var p = new Dictionary <string, object>(); p.Add("@link", search); var res = DbService.ExecuteScaler("SELECT [url] FROM BRShortLinks WHERE [link]=@link", CommandType.Text, p); if (res != null) { string link = (string)res; // shortlink success Response.Redirect(link, false); return; } } // really 404 -- todo, log it Response.Redirect("/page/504", false); } catch (Exception e2) { Response.Redirect("/page/504", false); //lLogoSvg.Text = e2.Message; } }
protected void Page_Load(object sender, EventArgs e) { try { // Check to see if exception should be logged if (Convert.ToBoolean(GlobalAttributesCache.Read().GetValue("Log404AsException"))) { ExceptionLogService.LogException(new Exception(string.Format("404 Error: {0}", Request.Url.AbsoluteUri)), Context); } // If this is an API call, set status code and exit if (Request.Url.Query.Contains(Request.Url.Authority + ResolveUrl("~/api/"))) { Response.StatusCode = 404; Response.Flush(); Response.End(); return; } // try to get site's 404 page SiteCache site = SiteCache.GetSiteByDomain(Request.Url.Host); if (site != null && site.PageNotFoundPageId.HasValue) { site.RedirectToPageNotFoundPage(); } else { Response.StatusCode = 404; logoImg.Src = ResolveUrl("~/Assets/Images/rock-logo.svg"); } } catch { Response.StatusCode = 404; logoImg.Src = ResolveUrl("~/Assets/Images/rock-logo.svg"); } }