Пример #1
0
 private void SetThreadCulture(Site site)
 {
     if (!string.IsNullOrEmpty(site.Culture))
     {
         var culture = CultureInfoHelper.CreateCultureInfo(site.Culture);
         Thread.CurrentThread.CurrentCulture = culture;
     }
 }
        internal void ResetContext()
        {
            if (!string.IsNullOrEmpty(this.PathInfo))
            {
                appRelativeCurrentExecutionFilePath = appRelativeCurrentExecutionFilePath.TrimEnd('/') + "/" + PathInfo;
            }
            if (SiteMappedContext != null)
            {
                //trim "~/"
                var trimedPath = appRelativeCurrentExecutionFilePath.Substring(2);

                this.Site = SiteMappedContext.Site;

                if (SiteMappedContext.RequestChannel == FrontRequestChannel.Preview)
                {
                    //preview url
                    #region dev~
                    //dev~site1/index
                    var paths = trimedPath.Split('/');

                    RequestUrl = Kooboo.Common.Web.UrlUtility.Combine(new[] { "/" }.Concat(paths.Skip(1)).ToArray());
                    if (this.Path.EndsWith("/") && !this.RequestUrl.EndsWith("/"))
                    {
                        RequestUrl = RequestUrl + "/";
                    }
                    appRelativeCurrentExecutionFilePath = "~" + RequestUrl;
                    #endregion
                }
                else
                {
                    var sitePathLength = 0;

                    var path = trimedPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    RequestUrl = UrlUtility.Combine(new[] { "/" }.Concat(path.Skip(sitePathLength)).ToArray());
                    if (this.Path.EndsWith("/") && !this.RequestUrl.EndsWith("/"))
                    {
                        RequestUrl = RequestUrl + "/";
                    }
                    appRelativeCurrentExecutionFilePath = "~" + RequestUrl;
                }

                if (!string.IsNullOrEmpty(Site.Culture))
                {
                    var culture = CultureInfoHelper.CreateCultureInfo(Site.Culture);
                    Thread.CurrentThread.CurrentCulture   = culture;
                    Thread.CurrentThread.CurrentUICulture = culture;
                }
            }

            //decode the request url. for chinese character
            this.RequestUrl = HttpUtility.UrlDecode(this.RequestUrl);
        }
Пример #3
0
        private void SetUICulture()
        {
            var user          = Kooboo.CMS.Account.Services.ServiceFactory.UserManager.Get(User.Identity.Name);
            var clientCulture = "en-us";

            if (Request.UserLanguages != null && Request.UserLanguages.Length > 0)
            {
                clientCulture = Request.UserLanguages[0];
            }
            var uiCulture = CultureInfoHelper.CreateCultureInfo(clientCulture);

            if (user != null && !string.IsNullOrEmpty(user.UICulture))
            {
                uiCulture = CultureInfoHelper.CreateCultureInfo(user.UICulture);
            }
            Thread.CurrentThread.CurrentUICulture = uiCulture;
        }
Пример #4
0
        private void SetUICulture(System.Web.Mvc.ActionExecutingContext filterContext)
        {
            var user          = Kooboo.CMS.Account.Services.ServiceFactory.UserManager.Get(filterContext.HttpContext.User.Identity.Name);
            var clientCulture = "en-us";

            if (filterContext.HttpContext.Request.UserLanguages != null && filterContext.HttpContext.Request.UserLanguages.Length > 0)
            {
                clientCulture = filterContext.HttpContext.Request.UserLanguages[0];
            }
            var uiCulture = CultureInfoHelper.CreateCultureInfo(clientCulture);

            if (user != null && !string.IsNullOrEmpty(user.UICulture))
            {
                uiCulture = CultureInfoHelper.CreateCultureInfo(user.UICulture);
            }
            Thread.CurrentThread.CurrentUICulture = uiCulture;
        }
Пример #5
0
        internal void ResolveSite()
        {
            if (IgnoreResolveSite(appRelativeCurrentExecutionFilePath))
            {
                return;
            }
            if (!string.IsNullOrEmpty(this.PathInfo))
            {
                appRelativeCurrentExecutionFilePath = appRelativeCurrentExecutionFilePath.TrimEnd('/') + "/" + PathInfo;
            }
            //trim "~/"
            var trimedPath = appRelativeCurrentExecutionFilePath.Substring(2);

            //if the RawUrl is not start with the debug site url.
            //http://www.site1.com/index
            //http://www.site1.com/en/index
            var siteProvider = Persistence.Providers.SiteProvider;

            if (!trimedPath.StartsWith(SiteHelper.PREFIX_FRONT_DEBUG_URL, StringComparison.InvariantCultureIgnoreCase))
            {
                #region RequestByHostName
                var host = GetRawHost(_request);
                RawSite = siteProvider.GetSiteByHostNameNPath(host, trimedPath);
                if (RawSite != null)
                {
                    sitePath = RawSite.SitePath;
                    var sitePathLength = 0;
                    if (!string.IsNullOrEmpty(sitePath))
                    {
                        sitePathLength = sitePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Length;
                        RequestChannel = FrontRequestChannel.HostNPath;
                    }
                    else
                    {
                        RequestChannel = FrontRequestChannel.Host;
                    }
                    var path = trimedPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    RequestUrl = UrlUtility.Combine(path.Skip(sitePathLength).ToArray());
                    appRelativeCurrentExecutionFilePath = "~/" + RequestUrl;
                }

                #endregion
            }
            else
            {
                #region dev~
                //dev~site1/index
                var path      = trimedPath.Split('/');
                var sitePaths = SiteHelper.SplitFullName(path[0].Substring(SiteHelper.PREFIX_FRONT_DEBUG_URL.Count()));

                RawSite = siteProvider.Get(Site.ParseSiteFromRelativePath(sitePaths));
                if (RawSite != null)
                {
                    RequestChannel = FrontRequestChannel.Debug;
                }

                RequestUrl = Kooboo.Web.Url.UrlUtility.Combine(path.Skip(1).ToArray());
                appRelativeCurrentExecutionFilePath = "~/" + RequestUrl;
                #endregion
            }

            if (RawSite != null)
            {
                if (RequestChannel == FrontRequestChannel.Debug || RequestChannel == FrontRequestChannel.Host || RequestChannel == FrontRequestChannel.HostNPath)
                {
                    Site = MatchSiteByVisitRule(RawSite);
                }

                //set current site repository
                Kooboo.CMS.Content.Models.Repository.Current = Site.GetRepository();

                if (!string.IsNullOrEmpty(Site.Culture))
                {
                    var culture = CultureInfoHelper.CreateCultureInfo(Site.Culture);
                    Thread.CurrentThread.CurrentCulture   = culture;
                    Thread.CurrentThread.CurrentUICulture = culture;
                }

                IsSSL = DetectSSLRequest(Site, _request);
            }

            //decode the request url. for chinese character
            this.RequestUrl = HttpUtility.UrlDecode(this.RequestUrl);
        }