Ejemplo n.º 1
0
        public virtual async Task <IActionResult> SetStore(
            [FromServices] IStoreService storeService,
            [FromServices] IStoreHelper _storeHelper,
            [FromServices] CommonSettings commonSettings,
            string store, string returnUrl = "")
        {
            var currentstoreid = _workContext.CurrentStore.Id;

            if (currentstoreid != store)
            {
                if (commonSettings.AllowToSelectStore)
                {
                    var selectedstore = await storeService.GetStoreById(store);

                    if (selectedstore != null)
                    {
                        await _storeHelper.SetStoreCookie(store);
                    }
                }
            }
            var prevStore = await storeService.GetStoreById(currentstoreid);

            var currStore = await storeService.GetStoreById(store);

            if (prevStore != null && currStore != null)
            {
                if (prevStore.Url != currStore.Url)
                {
                    return(Redirect(currStore.SslEnabled ? currStore.SecureUrl : currStore.Url));
                }
            }

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

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

            return(Redirect(returnUrl));
        }