void context_AuthorizeRequest(object sender, EventArgs e) { System.Web.HttpApplication app = sender as System.Web.HttpApplication; if (app == null) { return; } string fullUrl = BoxLib.RemoveAppNameFromUrl(app.Context.Request.RawUrl); string redirectUrl = null; if (fullUrl.StartsWith("/where-is-my-db.htm")) { return; } // if true, can see not published contents bool canSeeOnlyPublished = GetShowOnlyPublished(app, fullUrl); string url = BoxLib.RemoveAppNameFromUrl(app.Request.FilePath); redirectCache.TryGetValue(url, out redirectUrl); if (redirectUrl == null) { Services.CMSService cms = new Services.CMSService(); ContentHead c = null; try { c = cms.GetContentHeadByUrlAndKind(url, null, canSeeOnlyPublished); } catch (Exception ex) { var SQLexception = Box.Core.Services.SecurityService.GetSqlException(ex); if (SQLexception != null && !Box.Core.Services.SecurityService.IsDebug) { app.Context.Response.Redirect("~/where-is-my-db.htm#" + SQLexception.Number); } else { throw ex; } } if (c == null) { return; } redirectUrl = "~/box_templates/" + c.Kind + "/" + c.ContentUId; // only add at cache published urls if (canSeeOnlyPublished) { redirectCache.TryAdd(url, redirectUrl); } } app.Context.RewritePath(redirectUrl + "?" + app.Context.Request.QueryString); }
private void SetRedirectPath(HttpContext context) { //string fullUrl = BoxLib.RemoveAppNameFromUrl(context.Request.Path); string url = context.Request.Path.ToUriComponent();; string redirectUrl = null; bool useThumbRedirect = false; if (url.StartsWith("/where-is-my-db.htm") || url.StartsWith("/files/") || url.StartsWith("/box_templates/")) { return; } // if true, can see not published contents bool canSeeOnlyPublished = GetShowOnlyPublished(context, url); if (!context.Request.QueryString.HasValue) { redirectCache.TryGetValue(url, out redirectUrl); } if (redirectUrl == null) { Services.CMSService cms = context.RequestServices.GetService(typeof(Box.CMS.Services.CMSService)) as Services.CMSService; Models.ContentHead c = null; try { c = cms.GetContentHeadByUrlAndKind(url, null, canSeeOnlyPublished); } catch (System.Exception ex) { // var SQLexception = Box.Core.Services.SecurityService.GetSqlException(ex); // if (SQLexception != null && !Box.Core.Services.SecurityService.IsDebug) // app.Context.Response.Redirect("~/where-is-my-db.htm#" + SQLexception.Number); // else // throw ex; throw ex; } if (c == null) { return; } useThumbRedirect = SetThumbRedirectUrl(context, c); if (!useThumbRedirect) { redirectUrl = "/box_templates/" + c.Kind + "/" + c.ContentUId; // only add at cache published urls if (canSeeOnlyPublished) { redirectCache.TryAdd(url, redirectUrl); } } } if (!useThumbRedirect) { context.Request.Path = redirectUrl; // context.Request.HttpContext.Items["_boxOriginalUrl"] = url; } }