/// <summary> /// Raises the <see cref="BeforeRequestInit"/> event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected internal virtual void FireBeforeRequestInit(RequestInitEventArgs e) { if (BeforeRequestInit != null) { BeforeRequestInit(this, e); } }
/// <summary> /// Raises the <see cref="AfterRequestInit"/> event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected virtual void FireAfterRequestInit(RequestInitEventArgs e) { if (AfterRequestInit != null) { AfterRequestInit(this, e); } }
protected override void OnInit(EventArgs e) { base.OnInit(e); //This is only here for legacy if people arent' using master pages... //TODO: We need to test that this still works!! Or do we ?? if (!UmbracoSettings.UseAspNetMasterPages) { var args = new RequestInitEventArgs() { Page = _upage, PageId = _upage.PageID, Context = Context }; FireBeforeRequestInit(args); //if we are cancelling then return and don't proceed if (args.Cancel) { return; } var pageHolder = new umbraco.layoutControls.umbracoPageHolder { ID = "umbPageHolder" }; Page.Controls.Add(pageHolder); _upage.RenderPage(_upage.Template); var umbPageHolder = (layoutControls.umbracoPageHolder)Page.FindControl("umbPageHolder"); umbPageHolder.Populate(_upage); //fire the init finished event FireAfterRequestInit(args); } }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); // get the document request and the page _docRequest = UmbracoContext.Current.PublishedContentRequest; _upage = _docRequest.UmbracoPage; //we need to check this for backwards compatibility in case people still arent' using master pages if (UmbracoSettings.UseAspNetMasterPages) { var args = new RequestInitEventArgs() { Page = _upage, PageId = _upage.PageID, Context = Context }; FireBeforeRequestInit(args); //if we are cancelling then return and don't proceed if (args.Cancel) { return; } this.MasterPageFile = template.GetMasterPageName(_upage.Template); // reset the friendly path so it's used by forms, etc. Context.RewritePath(UmbracoContext.Current.OriginalRequestUrl.PathAndQuery); //fire the init finished event FireAfterRequestInit(args); } }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); // handle the infamous umbDebugShowTrace, etc Page.Trace.IsEnabled &= GlobalSettings.DebugMode && !String.IsNullOrWhiteSpace(Request["umbDebugShowTrace"]); // get the document request and the page _docRequest = UmbracoContext.Current.PublishedContentRequest; _upage = _docRequest.UmbracoPage; //we need to check this for backwards compatibility in case people still arent' using master pages if (UmbracoSettings.UseAspNetMasterPages) { var args = new RequestInitEventArgs() { Page = _upage, PageId = _upage.PageID, Context = Context }; FireBeforeRequestInit(args); //if we are cancelling then return and don't proceed if (args.Cancel) return; this.MasterPageFile = template.GetMasterPageName(_upage.Template); // reset the friendly path so it's used by forms, etc. Context.RewritePath(UmbracoContext.Current.OriginalRequestUrl.PathAndQuery); //fire the init finished event FireAfterRequestInit(args); } }
/// <summary>On event, before page request initialized for rendering.</summary> protected void UmbracoDefault_BeforeRequestInit(Object sender, RequestInitEventArgs e) { var httpRequest = HttpContext.Current.Request; var page = (UmbracoDefault)sender; var qsScreenType = httpRequest.QueryString["screentype"]; var currentScreenType = WebContext.GetStateScreenType(); var saveState = true; // Validate state. if(String.IsNullOrEmpty(qsScreenType) && String.IsNullOrEmpty(currentScreenType)) { // Validate browser. if(httpRequest.Browser.IsMobileDevice || httpRequest.UserAgent.ToLower().IndexOf("android") >= 0) { currentScreenType = "mobile"; } else { currentScreenType = "desktop"; } } else if(!String.IsNullOrEmpty(qsScreenType)) { // Validate HTTP query string. switch(qsScreenType) { case "mobile": currentScreenType = "mobile"; break; case "desktop_temp": currentScreenType = "desktop";saveState = false; break; case "desktop": default: currentScreenType = "desktop"; break; } } // Set state. if(saveState) {WebContext.SetStateScreenType(currentScreenType);} // Set main template (aka master page). try { switch(currentScreenType) { case "mobile": page.MasterPageFile = template.GetMasterPageName(e.Page.Template, "Mobile"); break; case "desktop": default: // Do nothing. break; } } catch(System.IO.DirectoryNotFoundException) { // Do nothing. } }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); using (Current.ProfilingLogger.DebugDuration <UmbracoDefault>("PreInit")) { // handle the infamous umbDebugShowTrace, etc Page.Trace.IsEnabled &= GlobalSettings.DebugMode && string.IsNullOrWhiteSpace(Request["umbDebugShowTrace"]) == false; // get the document request and the page _frequest = UmbracoContext.Current.PublishedRequest; _upage = _frequest.UmbracoPage; var args = new RequestInitEventArgs() { Page = _upage, PageId = _upage.PageID, Context = Context }; FireBeforeRequestInit(args); //if we are cancelling then return and don't proceed if (args.Cancel) { return; } var template = Current.Services.FileService.GetTemplate(_upage.Template); if (template != null) { var alias = template.MasterTemplateAlias; var file = alias.Replace(" ", "") + ".master"; var path = SystemDirectories.Masterpages + "/" + file; if (File.Exists(IOHelper.MapPath(VirtualPathUtility.ToAbsolute(path)))) { this.MasterPageFile = path; } else { this.MasterPageFile = SystemDirectories.Umbraco + "/masterPages/default.master"; } } // reset the friendly path so it's used by forms, etc. Context.RewritePath(UmbracoContext.Current.OriginalRequestUrl.PathAndQuery); //fire the init finished event FireAfterRequestInit(args); } }
protected override void OnInit(EventArgs e) { using (DisposableTimer.DebugDuration <UmbracoDefault>("Init")) { base.OnInit(e); //This is a special case for webforms since in some cases we may be POSTing to an MVC controller, adding TempData there and then redirecting // to a webforms handler. In that case we need to manually clear out the tempdata ourselves since this is normally the function of the base // MVC controller instance and since that is not executing, we'll deal with that here. //Unfortunately for us though, we can never know which TempDataProvider was used for the previous controller, by default it is the sessionstateprovider // but since the tempdataprovider is not a global mvc thing, it is only a per-controller thing, we can only just assume it will be the sessionstateprovider var provider = new SessionStateTempDataProvider(); //We create a custom controller context, the only thing that is referenced from this controller context in the sessionstateprovider is the HttpContext.Session // so we just need to ensure that is set var ctx = new ControllerContext(new HttpContextWrapper(Context), new RouteData(), new TempDataController()); provider.LoadTempData(ctx); //This is only here for legacy if people arent' using master pages... //TODO: We need to test that this still works!! Or do we ?? if (!UmbracoConfig.For.UmbracoSettings().Templates.UseAspNetMasterPages) { var args = new RequestInitEventArgs() { Page = _upage, PageId = _upage.PageID, Context = Context }; FireBeforeRequestInit(args); //if we are cancelling then return and don't proceed if (args.Cancel) { return; } var pageHolder = new umbraco.layoutControls.umbracoPageHolder { ID = "umbPageHolder" }; Page.Controls.Add(pageHolder); _upage.RenderPage(_upage.Template); var umbPageHolder = (layoutControls.umbracoPageHolder)Page.FindControl("umbPageHolder"); umbPageHolder.Populate(_upage); //fire the init finished event FireAfterRequestInit(args); } } }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); using (DisposableTimer.DebugDuration <UmbracoDefault>("PreInit")) { // handle the infamous umbDebugShowTrace, etc Page.Trace.IsEnabled &= GlobalSettings.DebugMode && string.IsNullOrWhiteSpace(Request["umbDebugShowTrace"]) == false; // get the document request and the page _docRequest = UmbracoContext.Current.PublishedContentRequest; _upage = _docRequest.UmbracoPage; //we need to check this for backwards compatibility in case people still arent' using master pages if (UmbracoSettings.UseAspNetMasterPages) { var args = new RequestInitEventArgs() { Page = _upage, PageId = _upage.PageID, Context = Context }; FireBeforeRequestInit(args); //if we are cancelling then return and don't proceed if (args.Cancel) { return; } this.MasterPageFile = template.GetMasterPageName(_upage.Template); // reset the friendly path so it's used by forms, etc. Context.RewritePath(UmbracoContext.Current.OriginalRequestUrl.PathAndQuery); //fire the init finished event FireAfterRequestInit(args); } } }
protected override void OnInit(EventArgs e) { using (DisposableTimer.DebugDuration<UmbracoDefault>("Init")) { base.OnInit(e); //This is only here for legacy if people arent' using master pages... //TODO: We need to test that this still works!! Or do we ?? if (!UmbracoConfig.For.UmbracoSettings().Templates.UseAspNetMasterPages) { var args = new RequestInitEventArgs() { Page = _upage, PageId = _upage.PageID, Context = Context }; FireBeforeRequestInit(args); //if we are cancelling then return and don't proceed if (args.Cancel) return; var pageHolder = new umbraco.layoutControls.umbracoPageHolder { ID = "umbPageHolder" }; Page.Controls.Add(pageHolder); _upage.RenderPage(_upage.Template); var umbPageHolder = (layoutControls.umbracoPageHolder)Page.FindControl("umbPageHolder"); umbPageHolder.Populate(_upage); //fire the init finished event FireAfterRequestInit(args); } } }
/// <summary> /// Raises the <see cref="AfterRequestInit"/> event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected virtual void FireAfterRequestInit(RequestInitEventArgs e) { if (AfterRequestInit != null) AfterRequestInit(this, e); }
/// <summary> /// Raises the <see cref="BeforeRequestInit"/> event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected internal virtual void FireBeforeRequestInit(RequestInitEventArgs e) { if (BeforeRequestInit != null) BeforeRequestInit(this, e); }
private void initUmbracoPage() { RequestInitEventArgs e = new RequestInitEventArgs(); e.Page = m_umbPage; if (m_umbPage != null) { e.PageId = m_umbPage.PageID; } e.Context = System.Web.HttpContext.Current; FireBeforeRequestInit(e); if (!e.Cancel) { if (!UmbracoSettings.EnableSplashWhileLoading || !content.Instance.isInitializing) { if (m_umbPage != null) { // Add page elements to global items try { System.Web.HttpContext.Current.Items.Add("pageElements", m_umbPage.Elements); } catch (ArgumentException) { System.Web.HttpContext.Current.Items.Remove("pageElements"); System.Web.HttpContext.Current.Items.Add("pageElements", m_umbPage.Elements); } string tempCulture = m_umbPage.GetCulture(); if (tempCulture != "") { System.Web.HttpContext.Current.Trace.Write("default.aspx", "Culture changed to " + tempCulture); System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(tempCulture); System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture; } if (!UmbracoSettings.UseAspNetMasterPages) { layoutControls.umbracoPageHolder pageHolder = new umbraco.layoutControls.umbracoPageHolder(); pageHolder.ID = "umbPageHolder"; Page.Controls.Add(pageHolder); m_umbPage.RenderPage(m_umbPage.Template); layoutControls.umbracoPageHolder umbPageHolder = (layoutControls.umbracoPageHolder)Page.FindControl("umbPageHolder"); umbPageHolder.Populate(m_umbPage); } } else { // If there's no published content, show friendly error if (umbraco.content.Instance.XmlContent.SelectSingleNode("/root/*") == null) { Response.Redirect(IO.SystemDirectories.Config + "/splashes/noNodes.aspx"); } else { GenerateNotFoundContent(); } } } else { Response.Redirect(IO.SystemDirectories.Config + "/splashes/booting.aspx?orgUrl=" + Request.Url); } FireAfterRequestInit(e); } }
private static void UmbracoDefaultAfterRequestInit(object sender, RequestInitEventArgs e) { var currentMember = Membership.GetUser(); var currentorder = UwebshopRequest.Current.OrderInfo ?? OrderHelper.GetOrder(); var orderRepository = IO.Container.Resolve<IOrderRepository>(); if (currentorder != null && (currentMember != null && currentorder.CustomerInfo.LoginName != currentMember.UserName)) { orderRepository.SetCustomer(currentorder.UniqueOrderId, currentMember.UserName); currentorder.CustomerInfo.LoginName = currentMember.UserName; if (currentMember.ProviderUserKey != null) { orderRepository.SetCustomerId(currentorder.UniqueOrderId, (int)currentMember.ProviderUserKey); currentorder.CustomerInfo.CustomerId = (int) currentMember.ProviderUserKey; } currentorder.ResetDiscounts(); currentorder.Save(); } if (currentorder != null && currentMember == null && !string.IsNullOrEmpty(currentorder.CustomerInfo.LoginName)) { orderRepository.SetCustomer(currentorder.UniqueOrderId, string.Empty); currentorder.CustomerInfo.LoginName = string.Empty; orderRepository.SetCustomerId(currentorder.UniqueOrderId, 0); currentorder.CustomerInfo.CustomerId = 0; currentorder.ResetDiscounts(); currentorder.Save(); } var cookie = HttpContext.Current.Request.Cookies["StoreInfo"]; if (cookie != null) { if (currentMember != null && !string.IsNullOrEmpty(cookie["Wishlist"])) { var wishlistId = cookie["Wishlist"]; Guid wishGuid; Guid.TryParse(wishlistId, out wishGuid); if (wishGuid != default(Guid) || wishGuid != Guid.Empty) { var wishlist = OrderHelper.GetOrder(wishGuid); wishlist.CustomerInfo.LoginName = currentMember.UserName; var userKey = 0; if (currentMember.ProviderUserKey != null) { int.TryParse(currentMember.ProviderUserKey.ToString(), out userKey); if (userKey != 0) { wishlist.CustomerInfo.CustomerId = userKey; } } var wishlistName = "Wishlist"; var wishlistCount = Customers.GetWishlists(currentMember.UserName).Count() + 1; wishlist.Name = string.Format("{0}{1}", wishlistName, wishlistCount); wishlist.Save(); cookie.Values.Remove("Wishlist"); } } } var paymentProvider = UwebshopRequest.Current.PaymentProvider; if (paymentProvider != null) { new PaymentRequestHandler().HandleuWebshopPaymentRequest(paymentProvider); Log.Instance.LogDebug("UmbracoDefaultAfterRequestInit paymentProvider: " + paymentProvider.Name); var paymentProviderTemplate = paymentProvider.Node.template; ((UmbracoDefault)sender).MasterPageFile = template.GetMasterPageName(paymentProviderTemplate); return; } // todo: ombouwen naar UwebshopRequest.Current.Category, UwebshopRequest.Current lostrekken (ivm speed) var currentCategoryId = HttpContext.Current.Request["resolvedCategoryId"]; var currentProductId = HttpContext.Current.Request["resolvedProductId"]; if (!string.IsNullOrEmpty(currentCategoryId)) //string.IsNullOrEmpty(currentProductUrl)) { int categoryId; if (!int.TryParse(currentCategoryId, out categoryId)) return; var categoryFromUrl = DomainHelper.GetCategoryById(categoryId); if (categoryFromUrl == null) return; if (categoryFromUrl.Disabled) { HttpContext.Current.Response.StatusCode = 404; HttpContext.Current.Response.Redirect(library.NiceUrl(int.Parse(GetCurrentNotFoundPageId())), true); return; } if (Access.HasAccess(categoryFromUrl.Id, categoryFromUrl.GetUmbracoPath(), Membership.GetUser())) { if (categoryFromUrl.Template != 0) { //umbraco.cms.businesslogic.template.Template.GetTemplate(currentCategory.Template).TemplateFilePath ((UmbracoDefault) sender).MasterPageFile = template.GetMasterPageName(categoryFromUrl.Template); //// get the template //var t = template.GetMasterPageName(currentCategory.Template); //// you did this and it works pre-4.10, right? //page.MasterPageFile = t; //// now this should work starting with 4.10 //e.Page.Template = t; } var altTemplate = HttpContext.Current.Request["altTemplate"]; if (!string.IsNullOrEmpty(altTemplate)) { var altTemplateId = umbraco.cms.businesslogic.template.Template.GetTemplateIdFromAlias(altTemplate); if (altTemplateId != 0) { ((UmbracoDefault) sender).MasterPageFile = template.GetMasterPageName(altTemplateId); } } } else { if (HttpContext.Current.User.Identity.IsAuthenticated) { HttpContext.Current.Response.Redirect(library.NiceUrl(Access.GetErrorPage(categoryFromUrl.GetUmbracoPath())), true); } HttpContext.Current.Response.Redirect(library.NiceUrl(Access.GetLoginPage(categoryFromUrl.GetUmbracoPath())), true); } } else if (!string.IsNullOrEmpty(currentProductId)) // else { int productId; if (!int.TryParse(currentProductId, out productId)) return; var productFromUrl = DomainHelper.GetProductById(productId); if (productFromUrl == null) return; if (Access.HasAccess(productFromUrl.Id, productFromUrl.Path(), Membership.GetUser())) { if (productFromUrl.Template != 0) { ((UmbracoDefault) sender).MasterPageFile = template.GetMasterPageName(productFromUrl.Template); } var altTemplate = HttpContext.Current.Request["altTemplate"]; if (!string.IsNullOrEmpty(altTemplate)) { var altTemplateId = umbraco.cms.businesslogic.template.Template.GetTemplateIdFromAlias(altTemplate); if (altTemplateId != 0) { ((UmbracoDefault) sender).MasterPageFile = template.GetMasterPageName(altTemplateId); } } } else { if (HttpContext.Current.User.Identity.IsAuthenticated) { HttpContext.Current.Response.Redirect(library.NiceUrl(Access.GetErrorPage(productFromUrl.Path())), true); } HttpContext.Current.Response.Redirect(library.NiceUrl(Access.GetLoginPage(productFromUrl.Path())), true); } } }
protected void UmbracoDefaultBeforeRequestInit(object sender, RequestInitEventArgs e) { try { //Domain.Core.Initialize.Init(); } catch (Exception) { //throw; } try { var currentNode = Node.GetCurrent(); if (ProductVariant.IsAlias(currentNode.NodeTypeAlias)) { var product = DomainHelper.GetProductById(currentNode.Parent.Id); if (product != null) HttpContext.Current.Response.RedirectPermanent(product.NiceUrl(), true); } else if (Product.IsAlias(currentNode.NodeTypeAlias)) { var product = DomainHelper.GetProductById(currentNode.Id); if (product != null) HttpContext.Current.Response.RedirectPermanent(product.NiceUrl(), true); } else if (Category.IsAlias(currentNode.NodeTypeAlias)) { var category = DomainHelper.GetCategoryById(currentNode.Id); if (category != null) HttpContext.Current.Response.RedirectPermanent( /* todo nicer */RazorExtensions.ExtensionMethods.NiceUrl(category), true); } } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { // intentionally left empty, because Umbraco will serve a 404 } }
private void initUmbracoPage() { RequestInitEventArgs e = new RequestInitEventArgs(); e.Page = m_umbPage; if(m_umbPage != null) e.PageId = m_umbPage.PageID; e.Context = System.Web.HttpContext.Current; FireBeforeRequestInit(e); if (!e.Cancel) { if (!UmbracoSettings.EnableSplashWhileLoading || !content.Instance.isInitializing) { if (m_umbPage != null) { // Add page elements to global items try { System.Web.HttpContext.Current.Items.Add("pageElements", m_umbPage.Elements); } catch (ArgumentException aex) { System.Web.HttpContext.Current.Items.Remove("pageElements"); System.Web.HttpContext.Current.Items.Add("pageElements", m_umbPage.Elements); } string tempCulture = m_umbPage.GetCulture(); if (tempCulture != "") { System.Web.HttpContext.Current.Trace.Write("default.aspx", "Culture changed to " + tempCulture); System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(tempCulture); System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture; } if (!UmbracoSettings.UseAspNetMasterPages) { layoutControls.umbracoPageHolder pageHolder = new umbraco.layoutControls.umbracoPageHolder(); pageHolder.ID = "umbPageHolder"; Page.Controls.Add(pageHolder); m_umbPage.RenderPage(m_umbPage.Template); layoutControls.umbracoPageHolder umbPageHolder = (layoutControls.umbracoPageHolder)Page.FindControl("umbPageHolder"); umbPageHolder.Populate(m_umbPage); } } else { // If there's no published content, show friendly error if (umbraco.content.Instance.XmlContent.SelectSingleNode("/root/*") == null) Response.Redirect(IO.SystemDirectories.Config + "/splashes/noNodes.aspx"); else { GenerateNotFoundContent(); } } } else { Response.Redirect(IO.SystemDirectories.Config + "/splashes/booting.aspx?orgUrl=" + Request.Url); } FireAfterRequestInit(e); } }