Exemple #1
0
        /// <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 void Page_Load(object sender, EventArgs e)
        {
            // Preprend the base URL if specified (which it should be if this is a subdomain of eastsussex.gov.uk)
            var siteContext = new HostingEnvironmentContext(HttpContext.Current.Request.Url);

            if (siteContext.BaseUrl != null)
            {
                var urlPrefix = siteContext.BaseUrl.ToString().TrimEnd('/');
                apple.Text   = urlPrefix + apple.Text;
                windows.Text = urlPrefix + windows.Text;
                search.Text  = urlPrefix + search.Text;
            }
        }
        /// <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 void Page_Load(object sender, EventArgs e)
        {
            // Preprend the base URL if specified (which it should be if this is a subdomain of eastsussex.gov.uk)
            var context = new HostingEnvironmentContext(HttpContext.Current.Request.Url);

            if (context.BaseUrl != null)
            {
                var urlPrefix = context.BaseUrl.ToString().TrimEnd('/');
                this.social.HRef  = urlPrefix + this.social.HRef;
                this.about.HRef   = urlPrefix + this.about.HRef;
                this.privacy.HRef = urlPrefix + this.privacy.HRef;
            }

            var tagManagerContext = new GoogleTagManagerContext();

            GoogleTagManagerContainerId = tagManagerContext.GoogleTagManagerContainerId;
        }
Exemple #3
0
        /// <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 void Page_Load(object sender, EventArgs e)
        {
            // Preprend the base URL if specified (which it should be if this is a subdomain of eastsussex.gov.uk)
            var context = new HostingEnvironmentContext(Request.Url);

            if (context.BaseUrl != null)
            {
                var urlPrefix = context.BaseUrl.ToString().TrimEnd('/');
                this.homeSmall.HRef = urlPrefix + this.homeSmall.HRef;
                this.contact.HRef   = urlPrefix + this.contact.HRef;

                // Because these are resources loaded by the page, rather than linking off to another page,
                // ensure the URL is protocol relative
                var colon = urlPrefix.IndexOf(":", StringComparison.OrdinalIgnoreCase);
                if (colon > -1)
                {
                    urlPrefix = urlPrefix.Substring(colon + 1);
                }
                this.logoSmall.Text = urlPrefix + this.logoSmall.Text;
            }
        }
        /// <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 void Page_Load(object sender, EventArgs e)
        {
            var siteContext = new HostingEnvironmentContext();

            // Preprend the base URL if specified (which it should be if this is a subdomain of eastsussex.gov.uk)
            if (siteContext.BaseUrl != null)
            {
                /*var urlPrefix = siteContext.BaseUrl.ToString().TrimEnd('/');
                 * this.chinese.HRef = urlPrefix + this.chinese.HRef;
                 * this.arabic.HRef = urlPrefix + this.arabic.HRef;
                 * this.urdu.HRef = urlPrefix + this.urdu.HRef;
                 * this.kurdish.HRef = urlPrefix + this.kurdish.HRef;
                 * this.portugese.HRef = urlPrefix + this.portugese.HRef;
                 * this.polish.HRef = urlPrefix + this.polish.HRef;
                 * this.slovakian.HRef = urlPrefix + this.slovakian.HRef;
                 * this.turkish.HRef = urlPrefix + this.turkish.HRef;*/
            }

            // Don't show translation option for the translation page itself or for HTTP status pages
            languages.Visible = (Regex.IsMatch(HttpContext.Current.Request.Url.ToString(), @"^((?!\/contactus\/emailus\/[a-z]*translation\.aspx).)*$", RegexOptions.IgnoreCase)) &&
                                (Regex.IsMatch(HttpContext.Current.Request.Url.ToString(), @"^((?!\/httpstatus).)*$", RegexOptions.IgnoreCase));
        }
        /// <summary>
        /// Selects most appropriate master page or MVC layout based on querystring or URL path
        /// </summary>
        /// <param name="queryString">The query string.</param>
        /// <param name="userAgent">The user agent.</param>
        /// <param name="viewEngine">The view engine to select the view for.</param>
        /// <param name="cookies">Cookies for the current response. Optional as now used only to delete the old cookie.</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>It requires master pages and/or MVC layouts to be set up in web.config similar to the following:</para>
        /// <example>
        ///   <code>
        /// &lt;configuration&gt;
        /// &lt;configSections&gt;
        /// &lt;sectionGroup name="Escc.EastSussexGovUK"&gt;
        /// &lt;section name="GeneralSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt;
        /// &lt;section name="DesktopMasterPages" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt;
        /// &lt;/sectionGroup&gt;
        /// &lt;/configSections&gt;
        /// &lt;Escc.EastSussexGovUK&gt;
        /// &lt;GeneralSettings&gt;
        /// &lt;add key="MasterPageParameterName" value="template" /&gt;
        /// &lt;/GeneralSettings&gt;
        /// &lt;DesktopMasterPages&gt;
        /// &lt;add key="/somefolder/somefolder/somepage.htm" value="~/master/CustomPage.master" /&gt;
        /// &lt;add key="/somefolder" value="~/master/CustomFolder.master" /&gt;
        /// &lt;add key="/" value="~/master/Desktop.master" /&gt;
        /// &lt;/DesktopMasterPages&gt;
        /// &lt;/Escc.EastSussexGovUK&gt;
        /// &lt;system.web&gt;
        /// &lt;httpModules&gt;
        /// &lt;add name="MasterPageModule" type="Escc.EastSussexGovUK.WebForms.MasterPageModule"/&gt;
        /// &lt;/httpModules&gt;
        /// &lt;/system.web&gt;
        /// &lt;/configuration&gt;
        /// </code>
        /// </example>
        /// <para>For MVC sites using Razor views, specify *.cshtml files wherever *.master is used above. The HTTP module is not needed for MVC.
        /// Instead add similar code to _ViewStart.cshtml.</para>
        /// </remarks>
        public static string SelectView(NameValueCollection queryString, string userAgent, ViewEngine viewEngine = ViewEngine.WebForms, HttpCookieCollection cookies = null)
        {
            // Grab settings from config and set up some defaults
            var generalSettings = ConfigurationManager.GetSection("Escc.EastSussexGovUK/GeneralSettings") as NameValueCollection;

            if (generalSettings == null)
            {
                generalSettings = ConfigurationManager.GetSection("EsccWebTeam.EastSussexGovUK/GeneralSettings") as NameValueCollection;
            }
            var configSettings = new Dictionary <EsccWebsiteView, NameValueCollection>();

            var configSettingsGroup = viewEngine == ViewEngine.WebForms ? "MasterPage" : "MvcLayout";

            configSettings[EsccWebsiteView.Desktop] = ConfigurationManager.GetSection("Escc.EastSussexGovUK/Desktop" + configSettingsGroup + "s") as NameValueCollection;
            if (configSettings[EsccWebsiteView.Desktop] == null)
            {
                configSettings[EsccWebsiteView.Desktop] = ConfigurationManager.GetSection("EsccWebTeam.EastSussexGovUK/Desktop" + configSettingsGroup + "s") as NameValueCollection;
            }

            configSettings[EsccWebsiteView.Plain] = ConfigurationManager.GetSection("Escc.EastSussexGovUK/Plain" + configSettingsGroup + "s") as NameValueCollection;
            if (configSettings[EsccWebsiteView.Plain] == null)
            {
                configSettings[EsccWebsiteView.Plain] = ConfigurationManager.GetSection("EsccWebTeam.EastSussexGovUK/Plain" + configSettingsGroup + "s") as NameValueCollection;
            }

            string preferredMasterPage = String.Empty;
            var    preferredView       = EsccWebsiteView.Desktop;

            // Are we set up to accept user requests for a master page?
            var acceptUserRequest = (generalSettings != null && !String.IsNullOrEmpty(generalSettings["MasterPageParameterName"]));

            // If a master page is requested in the querystring that trumps everything *for this request only*
            if (acceptUserRequest && !String.IsNullOrEmpty(queryString[generalSettings["MasterPageParameterName"]]))
            {
                preferredView = AssignMasterPageFromUserRequest(generalSettings, configSettings, configSettingsGroup, preferredView, queryString[generalSettings["MasterPageParameterName"]]);
            }

            // We now know which type of master page we want to use, so now get the path to the master page file.
            // Get master page from config based on folder if available, otherwise based on a single setting.
            if (configSettings.ContainsKey(preferredView) && configSettings[preferredView] != null)
            {
                // A CMS may change the URL requested by the user to that of the template, so use the corrected URL provided by HostingEnvironmentContext
                var siteContext = new HostingEnvironmentContext();
                preferredMasterPage = AssignMasterPageByFolder(HttpContext.Current.Request.Url, configSettings[preferredView], preferredMasterPage);
            }
            else if (generalSettings != null)
            {
                var configKey = preferredView + configSettingsGroup;
                if (!String.IsNullOrEmpty(generalSettings[configKey]))
                {
                    preferredMasterPage = generalSettings[configKey];
                }
            }

            if (viewEngine == ViewEngine.Mvc && String.IsNullOrEmpty(preferredMasterPage))
            {
                throw new ConfigurationErrorsException("The path to the selected MVC layout was not specified. Set the path in the Escc.EastSussexGovUK/GeneralSettings/add[@key='" + preferredView + configSettingsGroup + "'] element in web.config.");
            }

            // We used to use a cookie. Delete it if found. These cookies were set to last for 50 years!
            DeleteCookie(cookies, "template1", ".eastsussex.gov.uk");

            return(preferredMasterPage);
        }
Exemple #6
0
        /// <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();

            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.Controls.Add(new LiteralControl("<h2 class=\"aural\">You are here</h2>"));
                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.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>"));
            }
        }