Ejemplo n.º 1
0
        public ActionResult ChangeCulture(string cultureName)
        {
            var translatedUrlFound = false;

            if (Services.WorkContext.HttpContext.Request.UrlReferrer == null)
            {
                return(new HttpStatusCodeResult(404));
            }
            if (string.IsNullOrEmpty(cultureName))
            {
                return(new HttpStatusCodeResult(404));
            }
            var urlPrefix          = Services.WorkContext.Resolve <ShellSettings>().RequestUrlPrefix;
            var requestUrl         = Utils.GetReturnUrl(Services.WorkContext.HttpContext.Request, urlPrefix);
            var requestQuerystring = Services.WorkContext.HttpContext.Request.UrlReferrer.Query;
            var context            = new LocalizableRouteContext(requestUrl, requestQuerystring, cultureName);

            foreach (var provider in _localizableRouteService.OrderBy(x => x.Priority))
            {
                if (provider.TryFindLocalizedUrl(context))
                {
                    translatedUrlFound = true;
                }
            }

            // Set the cookie even if a translatedUrl has not been found (for coeherence with the user choice)
            _cpServices.SaveCultureCookie(cultureName, this.HttpContext);
            return(this.RedirectLocal(context.RedirectLocalUrl));
        }
Ejemplo n.º 2
0
        public ActionResult ChangeCulture(string cultureName)
        {
            // add try catch for identify the error
            // temporary try catch
            try
            {
                if (Services.WorkContext.HttpContext.Request.UrlReferrer == null)
                {
                    return(new HttpStatusCodeResult(404));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "UrlReferrer Request Header: " + string.Join(Environment.NewLine, Services.WorkContext.HttpContext.Request.Headers));
                return(new HttpStatusCodeResult(404));
            }

            if (string.IsNullOrEmpty(cultureName))
            {
                return(new HttpStatusCodeResult(404));
            }
            var urlPrefix          = Services.WorkContext.Resolve <ShellSettings>().RequestUrlPrefix;
            var requestUrl         = Utils.GetReturnUrl(Services.WorkContext.HttpContext.Request, urlPrefix);
            var requestQuerystring = Services.WorkContext.HttpContext.Request.UrlReferrer.Query;
            var context            = new LocalizableRouteContext(requestUrl, requestQuerystring, cultureName);

            foreach (var provider in _localizableRouteService.OrderBy(x => x.Priority))
            {
                provider.TryFindLocalizedUrl(context);
            }

            // Set the cookie even if a translatedUrl has not been found (for coeherence with the user choice)
            _cpServices.SaveCultureCookie(cultureName, this.HttpContext);

            // add try catch for identify the error
            try
            {
                return(this.RedirectLocal(context.RedirectLocalUrl));
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "RedirectLocalUrl Request Header: " + string.Join(Environment.NewLine, Services.WorkContext.HttpContext.Request.Headers));
                return(new HttpStatusCodeResult(404));
            }
        }