/// <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="System.EventArgs"/> instance containing the event data.</param> protected new void Page_Load(object sender, EventArgs e) { // Configure remote master page var httpClientProvider = new HttpClientProvider(new ConfigurationProxyProvider()); var masterPageSettings = new RemoteMasterPageSettingsFromConfig(); var forceCacheRefresh = (Page.Request.QueryString["ForceCacheRefresh"] == "1"); // Provide a way to force an immediate update of the cache var remoteMasterPageClient = new RemoteMasterPageHtmlProvider(masterPageSettings.MasterPageControlUrl(), httpClientProvider, Request.UserAgent, new RemoteMasterPageMemoryCacheProvider { CacheDuration = TimeSpan.FromMinutes(masterPageSettings.CacheTimeout()) }, forceCacheRefresh); this.htmlTag.HtmlControlProvider = remoteMasterPageClient; this.metadataFullScreen.HtmlControlProvider = remoteMasterPageClient; if (this.headerFullScreen != null) { this.headerFullScreen.HtmlControlProvider = remoteMasterPageClient; } this.scriptsFullScreen.HtmlControlProvider = remoteMasterPageClient; // Support web fonts required by the current skin if (Skin != null) { var fontsHtml = new StringBuilder(); foreach (var font in Skin.RequiresGoogleFonts()) { fontsHtml.Append("<link href=\"").Append(font.FontUrl).Append("\" rel=\"stylesheet\" type=\"text/css\" />"); } this.fonts.Text = fontsHtml.ToString(); AddClientDependencies(Skin); } // Support web chat var context = new HostingEnvironmentContext(HttpContext.Current.Request.Url); if (context.WebChatSettingsUrl != null) { var webChat = new WebChat(); var webChatApiSettings = Options.Create(new WebChatApiSettings { WebChatSettingsUrl = context.WebChatSettingsUrl, CacheMinutes = context.WebChatSettingsCacheDuration }); webChat.WebChatSettings = new WebChatSettingsFromApi(webChatApiSettings, httpClientProvider, new ApplicationCacheStrategy <WebChatSettings>()).ReadWebChatSettings().Result; webChat.WebChatSettings.PageUrl = new Uri(Request.Url.AbsolutePath, UriKind.Relative); if (webChat.IsRequired()) { AddClientDependencies(webChat); } } // Run the base method as well base.Page_Load(sender, e); }
/// <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="System.EventArgs"/> instance containing the event data.</param> protected new void Page_Load(object sender, EventArgs e) { // Apply selected text size to page var textSize = new TextSize(Request.Cookies, Request.QueryString); int baseTextSize = textSize.CurrentTextSize(); if (baseTextSize > 1) { // Add a space if there are other classes, then add to body tag this.bodyclass.Controls.Add(new LiteralControl(" size" + baseTextSize.ToString(CultureInfo.InvariantCulture))); } // Support web fonts required by the current skin if (Skin != null) { var fontsHtml = new StringBuilder(); foreach (var font in Skin.RequiresGoogleFonts()) { fontsHtml.Append("<link href=\"").Append(font.FontUrl).Append("\" rel=\"stylesheet\" type=\"text/css\" />"); } if (Skin.RequiresTypekitFonts().Any()) { foreach (var font in Skin.RequiresTypekitFonts()) { fontsHtml.Append("<script src=\"").Append(font.TypekitUrl).Append("\"></script>"); } this.Typekit.Visible = true; } this.fonts.Text = fontsHtml.ToString(); AddClientDependencies(Skin); } // Support web chat var context = new HostingEnvironmentContext(); if (context.WebChatSettingsUrl != null) { var webChat = new WebChat(); webChat.WebChatSettings = new WebChatSettingsFromApi(context.WebChatSettingsUrl, new ConfigurationProxyProvider(), new ApplicationCacheStrategy <WebChatSettings>(TimeSpan.FromMinutes(context.WebChatSettingsCacheDuration))).ReadWebChatSettings(); webChat.WebChatSettings.PageUrl = new Uri(Request.Url.AbsolutePath, UriKind.Relative); if (webChat.IsRequired()) { AddClientDependencies(webChat); } } // Run the base method as well base.Page_Load(sender, e); }
/// <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="System.EventArgs"/> instance containing the event data.</param> protected new void Page_Load(object sender, EventArgs e) { // Support web fonts required by the current skin if (Skin != null) { var fontsHtml = new StringBuilder(); foreach (var font in Skin.RequiresGoogleFonts()) { fontsHtml.Append("<link href=\"").Append(font.FontUrl).Append("\" rel=\"stylesheet\" type=\"text/css\" />"); } if (Skin.RequiresTypekitFonts().Any()) { foreach (var font in Skin.RequiresTypekitFonts()) { fontsHtml.Append("<script src=\"").Append(font.TypekitUrl).Append("\"></script>"); } this.Typekit.Visible = true; } this.fonts.Text = fontsHtml.ToString(); AddClientDependencies(Skin); } // Support web chat var context = new HostingEnvironmentContext(); if (context.WebChatSettingsUrl != null) { var webChat = new WebChat(); webChat.WebChatSettings = new WebChatSettingsFromApi(context.WebChatSettingsUrl, new ConfigurationProxyProvider(), new ApplicationCacheStrategy <WebChatSettings>(TimeSpan.FromMinutes(context.WebChatSettingsCacheDuration))).ReadWebChatSettings(); webChat.WebChatSettings.PageUrl = new Uri(Request.Url.AbsolutePath, UriKind.Relative); if (webChat.IsRequired()) { AddClientDependencies(webChat); } } // Run the base method as well base.Page_Load(sender, e); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { // Turn breadcrumb trail levels into list items var listItems = new List <HtmlGenericControl>(); var breadcrumbTrail = this.BreadcrumbProvider.BuildTrail(); var siteContext = new HostingEnvironmentContext(HttpContext.Current.Request.Url); foreach (string key in breadcrumbTrail.Keys) { var listItem = new HtmlGenericControl("li"); if (String.IsNullOrEmpty(breadcrumbTrail[key])) { listItem.InnerText = key; } else { HtmlAnchor link = new HtmlAnchor(); link.InnerText = key; link.HRef = breadcrumbTrail[key]; listItem.Controls.Add(link); } listItems.Add(listItem); } // add the finished list to the "home" list if (listItems.Count > 0) { HtmlGenericControl list = new HtmlGenericControl("ol"); list.Attributes["class"] = "breadcrumb large"; for (var i = 0; i < listItems.Count; i++) { listItems[i].Attributes["class"] = (i == (listItems.Count - 1)) ? "current" : "up"; list.Controls.Add(listItems[i]); } this.Attributes["aria-label"] = "You are here"; for (var i = 0; i < list.Controls.Count; i++) { var item = (list.Controls[i] as HtmlGenericControl); item.Attributes["class"] = (item.Attributes["class"] + " level" + (i + 1).ToString(CultureInfo.InvariantCulture)).Trim(); if (item.Controls[0] is HtmlAnchor) { item.Controls.AddAt(0, new LiteralControl("<span class=\"aural\">Level " + (i + 1).ToString(CultureInfo.CurrentCulture) + ": </span>")); } else { item.Attributes["aria-current"] = "page"; item.Controls.AddAt(0, new LiteralControl("<span class=\"aural\">Current level: </span>")); } } this.Controls.Add(list); //==================================== Structured Breadcrumbs =====================================================\\ // Create structed breadcrumb markup for Google. // https://developers.google.com/search/docs/data-types/breadcrumbs // Json-LD script is built as a string. StringBuilder breadcrumbScript = new StringBuilder(); breadcrumbScript.Append("{ \"@context\": \"http://schema.org\", \"@type\": \"BreadcrumbList\", \"itemListElement\": ["); var position = 1; // The breadcrumbTrail collection contains all the data needed for position, id and name. foreach (var item in breadcrumbTrail) { breadcrumbScript.Append("{\"@type\" : \"ListItem\",\"position\": " + position + " ,\"item\": {\"@id\": " + "\"" + item.Value + "\","); // if the breadcrumb is not the last in the collection, keep script open. if (position != breadcrumbTrail.Count) { breadcrumbScript.Append("\"name\": " + "\"" + item.Key + "\"}},"); } // if the breadcrumb is the last in the collection, close the script else { breadcrumbScript.Append("\"name\": " + "\"" + item.Key + "\"}}]}"); } position++; } // Add the script string to the page within <script> tags of type 'application/ld+json' HtmlGenericControl script = new HtmlGenericControl("script"); script.Attributes.Add("type", "application/ld+json"); script.InnerHtml = breadcrumbScript.ToString(); this.Controls.Add(script); //===================================Structured Breadcrumbs======================================================\\ } // If no breadcrumb found and we're running on an internal host name, show a message. // Otherwise it's an easy thing for the developer to miss. else if (!siteContext.IsPublicUrl) { this.Controls.Add(new LiteralControl("<p><strong>You need to add a breadcrumb trail. See the documentation for " + this.BreadcrumbProvider.GetType().FullName + ".</strong></p>")); } }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { // Ensure controls are visible by default this.Visible = true; // Look for various reasons why controls may need to be hidden // Hide based on master page var viewSelector = new WebFormsViewSelector(); if (Desktop != null && Desktop.Value != viewSelector.CurrentViewIs(Page.MasterPageFile, EsccWebsiteView.Desktop)) { HideContents(); return; } if (Plain != null && Plain.Value != viewSelector.CurrentViewIs(Page.MasterPageFile, EsccWebsiteView.Plain)) { HideContents(); return; } if (FullScreen != null && FullScreen.Value != viewSelector.CurrentViewIs(Page.MasterPageFile, EsccWebsiteView.FullScreen)) { HideContents(); return; } // Hide based on user var libraryContext = new LibraryCatalogueContext(HttpContext.Current.Request.UserAgent); if (LibraryCatalogue != null && LibraryCatalogue.Value != libraryContext.RequestIsFromLibraryCatalogueMachine()) { HideContents(); return; } if (!String.IsNullOrEmpty(Groups)) { var settings = new ActiveDirectorySettingsFromConfiguration(); var permissions = new LogonIdentityGroupMembershipChecker(settings.DefaultDomain, new ActiveDirectoryMemoryCache()); if (!permissions.UserIsInGroup(Groups.SplitAndTrim(';'))) { HideContents(); return; } } // Hide based on location if (!String.IsNullOrEmpty(this.UrlMatch) && !Regex.IsMatch(HttpContext.Current.Request.Url.ToString(), this.UrlMatch, RegexOptions.IgnoreCase)) { HideContents(); return; } var context = new HostingEnvironmentContext(HttpContext.Current.Request.Url); if (Public != null && Public.Value != context.IsPublicUrl) { HideContents(); return; } // Hide based on date if (this.After.HasValue && DateTime.Now.ToUkDateTime() <= this.After) { HideContents(); return; } if (this.Before.HasValue && DateTime.Now.ToUkDateTime() >= this.Before) { HideContents(); return; } }
/// <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="System.EventArgs"/> instance containing the event data.</param> protected new void Page_Load(object sender, EventArgs e) { // Configure remote master page var httpClientProvider = new HttpClientProvider(new ConfigurationProxyProvider()); var masterPageSettings = new RemoteMasterPageSettingsFromConfig(); var forceCacheRefresh = (Page.Request.QueryString["ForceCacheRefresh"] == "1"); // Provide a way to force an immediate update of the cache var remoteMasterPageClient = new RemoteMasterPageHtmlProvider(masterPageSettings.MasterPageControlUrl(), httpClientProvider, Request.UserAgent, new RemoteMasterPageMemoryCacheProvider { CacheDuration = TimeSpan.FromMinutes(masterPageSettings.CacheTimeout()) }, forceCacheRefresh); this.htmlTag.HtmlControlProvider = remoteMasterPageClient; this.metadataDesktop.HtmlControlProvider = remoteMasterPageClient; this.aboveHeaderDesktop.HtmlControlProvider = remoteMasterPageClient; if (this.headerDesktop != null) { this.headerDesktop.HtmlControlProvider = remoteMasterPageClient; } if (this.footerDesktop != null) { this.footerDesktop.HtmlControlProvider = remoteMasterPageClient; } this.scriptsDesktop.HtmlControlProvider = remoteMasterPageClient; // Apply selected text size to page var textSize = new TextSize(Request.Cookies?["textsize"]?.Value, Request.QueryString); int baseTextSize = textSize.CurrentTextSize(); if (baseTextSize > 1) { // Add a space if there are other classes, then add to body tag this.bodyclass.Controls.Add(new LiteralControl(" size" + baseTextSize.ToString(CultureInfo.InvariantCulture))); } // Support web fonts required by the current skin if (Skin != null) { var fontsHtml = new StringBuilder(); foreach (var font in Skin.RequiresGoogleFonts()) { fontsHtml.Append("<link href=\"").Append(font.FontUrl).Append("\" rel=\"stylesheet\" type=\"text/css\" />"); } this.fonts.Text = fontsHtml.ToString(); AddClientDependencies(Skin); } // Support web chat var context = new HostingEnvironmentContext(HttpContext.Current.Request.Url); if (context.WebChatSettingsUrl != null) { var webChat = new WebChat(); var webChatApiSettings = Options.Create(new WebChatApiSettings { WebChatSettingsUrl = context.WebChatSettingsUrl, CacheMinutes = context.WebChatSettingsCacheDuration }); webChat.WebChatSettings = new WebChatSettingsFromApi(webChatApiSettings, httpClientProvider, new ApplicationCacheStrategy <WebChatSettings>()).ReadWebChatSettings().Result; webChat.WebChatSettings.PageUrl = new Uri(Request.Url.AbsolutePath, UriKind.Relative); if (webChat.IsRequired()) { AddClientDependencies(webChat); } } // Run the base method as well base.Page_Load(sender, e); }