Ejemplo n.º 1
0
        public static void SetCountry(SiteCulture culture)
        {
            //reset cookie
            //BBAReman.CountryCookie.ResetCookie(culture.ThreeDigitISORegionCode);

            //set locale!
            SetUserLocale(culture.CultureInfo, culture.UICultureInfo);
        }
Ejemplo n.º 2
0
        public static SiteCulture GetCulture(string countryCode)
        {
            //either from the current UI culture or from the URL string
            SiteCulture culture = SiteGlobalization.DefaultCulture;

            switch (countryCode.Length)
            {
            case 2:
                culture = SiteGlobalization.BBACultures.Keys.Contains(countryCode.ToUpper()) ? SiteGlobalization.BBACultures[countryCode.ToUpper()] : culture;
                break;

            case 3:
                culture = SiteGlobalization.BBACultures.Values.SingleOrDefault(x => x.ThreeDigitISORegionCode == countryCode);
                break;
            }
            return(culture);
        }
Ejemplo n.º 3
0
        protected void Application_BeginRequest(Object sender, EventArgs e)
        {
            string rawUrl = HttpContext.Current.Request.RawUrl;

            ///* check the url has a country code in the title */
            //if (!HttpContext.Current.Request.CurrentExecutionFilePathExtension.Equals(".aspx"))
            //{
            //    if (HttpContext.Current.Request.CurrentExecutionFilePathExtension.Equals(string.Empty) && (HttpContext.Current.Request.FilePath.Length == 3))
            //    {
            //        //Could be countrycode with no ending slash
            //        rawUrl = rawUrl + "/";
            //    }
            //    else
            //        return;
            //}


            //check for 2 characters wrapped in forward slashes eg. /en/
            string      countryCode = Utility.GetCountryCodeFromUrl(rawUrl);
            SiteCulture bbaCulture  = SiteGlobalization.DefaultCulture;


            if (string.IsNullOrEmpty(countryCode))
            {
                //check cookie
                if (!string.IsNullOrEmpty(Utility.GetCookieValue()))
                {
                    string threeDigitIsoRegionCodeCookie = Utility.GetCookieValue();
                    bbaCulture = SiteGlobalization.BBACultures.Values.FirstOrDefault(x => x.ThreeDigitISORegionCode.Equals(threeDigitIsoRegionCodeCookie, StringComparison.InvariantCultureIgnoreCase));
                    if (bbaCulture != null && !string.IsNullOrEmpty(bbaCulture.TwoDigitISORegionCode))
                    {
                        countryCode = bbaCulture.TwoDigitISORegionCode;
                    }
                }

                //check the referer.
                if (string.IsNullOrEmpty(countryCode) && HttpContext.Current.Request.UrlReferrer != null && !string.IsNullOrEmpty(HttpContext.Current.Request.UrlReferrer.AbsolutePath))
                {
                    countryCode = Utility.GetCountryCodeFromUrl(HttpContext.Current.Request.UrlReferrer.AbsolutePath);
                }

                //finally browser
                countryCode = string.IsNullOrEmpty(countryCode) ? Utility.Get2DigitCountryCodeFromBrowser().ToLower() : countryCode;

                string redirectUrl = string.Format("/{0}{1}", countryCode, rawUrl);
                HttpContext.Current.Response.RedirectPermanent(redirectUrl.ToLower());
            }

            /* is the country code valid ? */
            bbaCulture = SiteGlobalization.BBACultures.Values.FirstOrDefault(x => x.TwoDigitISORegionCode.Equals(countryCode, StringComparison.InvariantCultureIgnoreCase));

            if (bbaCulture == null || string.IsNullOrEmpty(bbaCulture.ThreeDigitISORegionCode))
            {
                HttpContext.Current.Response.RedirectPermanent(string.Format("/{0}/default.aspx", SiteGlobalization.DefaultCulture.TwoDigitISORegionCode.ToLower()));
            }

            if (HttpContext.Current.Request.FilePath.EndsWith("/" + countryCode))
            {
                HttpContext.Current.Response.RedirectPermanent(string.Format("/{0}/default.aspx", countryCode.ToLower()));
            }

            /* set the default cutlure */
            Utility.SetCountry(bbaCulture);
        }