Ejemplo n.º 1
0
        public virtual async Task <IActionResult> SetLanguage(int langid, string returnUrl = "")
        {
            var language = await _languageService.GetLanguageByIdAsync(langid);

            if (!language?.Published ?? false)
            {
                language = await _workContext.GetWorkingLanguageAsync();
            }

            //home page
            if (string.IsNullOrEmpty(returnUrl))
            {
                returnUrl = Url.RouteUrl("Homepage");
            }

            //language part in URL
            if (_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
            {
                //remove current language code if it's already localized URL
                if ((await returnUrl.IsLocalizedUrlAsync(Request.PathBase, true)).IsLocalized)
                {
                    returnUrl = returnUrl.RemoveLanguageSeoCodeFromUrl(Request.PathBase, true);
                }

                //and add code of passed language
                returnUrl = returnUrl.AddLanguageSeoCodeToUrl(Request.PathBase, true, language);
            }

            await _workContext.SetWorkingLanguageAsync(language);

            //prevent open redirection attack
            if (!Url.IsLocalUrl(returnUrl))
            {
                returnUrl = Url.RouteUrl("Homepage");
            }

            return(Redirect(returnUrl));
        }
Ejemplo n.º 2
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> SetLanguage(int langid, string returnUrl = "")
        {
            var language = await _languageService.GetLanguageByIdAsync(langid);

            if (language != null)
            {
                await _workContext.SetWorkingLanguageAsync(language);
            }

            //home page
            if (string.IsNullOrEmpty(returnUrl))
            {
                returnUrl = Url.Action("Index", "Home", new { area = AreaNames.Admin });
            }

            //prevent open redirection attack
            if (!Url.IsLocalUrl(returnUrl))
            {
                return(RedirectToAction("Index", "Home", new { area = AreaNames.Admin }));
            }

            return(Redirect(returnUrl));
        }