/// <summary>
            /// Called before the action executes, after model binding is complete
            /// </summary>
            /// <param name="context">A context for action filters</param>
            public void OnActionExecuting(ActionExecutingContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                if (context.HttpContext.Request == null)
                {
                    return;
                }

                //only in GET requests
                if (!context.HttpContext.Request.Method.Equals(WebRequestMethods.Http.Get, StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }

                if (!DataSettingsManager.DatabaseIsInstalled)
                {
                    return;
                }

                //whether SEO friendly URLs are enabled
                if (!_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
                {
                    return;
                }

                //ensure that this route is registered and localizable (LocalizedRoute in RouteProvider)
                if (context.RouteData?.Routers == null || !context.RouteData.Routers.ToList().Any(r => r is LocalizedRoute))
                {
                    return;
                }

                //check whether current page URL is already localized URL
                var pageUrl = _webHelper.GetRawUrl(context.HttpContext.Request);

                if (pageUrl.IsLocalizedUrl(context.HttpContext.Request.PathBase, true, out Language _))
                {
                    return;
                }

                //not localized yet, so redirect to the page with working language SEO code
                pageUrl        = pageUrl.AddLanguageSeoCodeToUrl(context.HttpContext.Request.PathBase, true, _workContext.WorkingLanguage);
                context.Result = new RedirectResult(pageUrl, false);
            }
예제 #2
0
            /// <summary>
            /// Called before the action executes, after model binding is complete
            /// </summary>
            /// <param name="context">A context for action filters</param>
            public void OnActionExecuting(ActionExecutingContext context)
            {
                if (context == null || context.HttpContext == null || context.HttpContext.Request == null)
                {
                    return;
                }

                if (!DataSettingsHelper.DatabaseIsInstalled())
                {
                    return;
                }

                //only in GET requests
                if (!HttpMethods.IsGet(context.HttpContext.Request.Method))
                {
                    return;
                }

                //whether SEO friendly URLs are enabled
                //if (!_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
                //    return;


                //ensure that this route is registered and localizable (LocalizedRoute in RouteProvider)
                if (context.RouteData == null ||
                    context.RouteData.Routers == null ||
                    !context.RouteData.Routers.ToList().Any(r => r is LocalizedRoute))
                {
                    return;
                }

                //check whether current page URL is already localized URL
                var pageUrl = _webHelper.GetRawUrl(context.HttpContext.Request);

                //if (pageUrl.IsLocalizedUrl(context.HttpContext.Request.PathBase, true, out Language language))
                //    return;

                ////not localized yet, so redirect to the page with working language SEO code
                //pageUrl = pageUrl.AddLanguageSeoCodeToUrl(context.HttpContext.Request.PathBase, true, _workContext.WorkingLanguage);
                context.Result = new RedirectResult(pageUrl, false);
            }
예제 #3
0
        public virtual IActionResult GeneralRedirect()
        {
            // use Request.RawUrl, for instance to parse out what was invoked
            // this regex will extract anything between a "/" and a ".aspx"
            var regex        = new Regex(@"(?<=/).+(?=\.aspx)", RegexOptions.Compiled);
            var rawUrl       = _webHelper.GetRawUrl(this.HttpContext.Request);
            var aspxfileName = regex.Match(rawUrl).Value.ToLowerInvariant();

            switch (aspxfileName)
            {
            case "profile":
            {
                return(RedirectUserProfile(_webHelper.QueryString <string>("UserId")));
            }

            case "compareproducts":
            {
                return(RedirectToRoutePermanent("CompareProducts"));
            }

            case "contactus":
            {
                return(RedirectToRoutePermanent("ContactUs"));
            }

            case "passwordrecovery":
            {
                return(RedirectToRoutePermanent("PasswordRecovery"));
            }

            case "login":
            {
                return(RedirectToRoutePermanent("Login"));
            }

            case "register":
            {
                return(RedirectToRoutePermanent("Register"));
            }

            case "newsarchive":
            {
                return(RedirectToRoutePermanent("NewsArchive"));
            }

            case "search":
            {
                return(RedirectToRoutePermanent("ProductSearch"));
            }

            case "sitemap":
            {
                return(RedirectToRoutePermanent("Sitemap"));
            }

            case "recentlyaddedproducts":
            {
                return(RedirectToRoutePermanent("NewProducts"));
            }

            case "shoppingcart":
            {
                return(RedirectToRoutePermanent("ShoppingCart"));
            }

            case "wishlist":
            {
                return(RedirectToRoutePermanent("Wishlist"));
            }

            case "CheckGiftCardBalance":
            {
                return(RedirectToRoutePermanent("CheckGiftCardBalance"));
            }

            default:
                break;
            }

            //no permanent redirect in this case
            return(RedirectToRoute("HomePage"));
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> GeneralRedirect()
        {
            // use Request.RawUrl, for instance to parse out what was invoked
            // this regex will extract anything between a "/" and a ".aspx"
            var regex        = new Regex(@"(?<=/).+(?=\.aspx)", RegexOptions.Compiled);
            var rawUrl       = _webHelper.GetRawUrl(HttpContext.Request);
            var aspxfileName = regex.Match(rawUrl).Value.ToLowerInvariant();

            switch (aspxfileName)
            {
            //URL without rewriting
            case "product":
            {
                return(await RedirectProduct(_webHelper.QueryString <string>("productid"), false));
            }

            case "category":
            {
                return(await RedirectCategory(_webHelper.QueryString <string>("categoryid"), false));
            }

            case "manufacturer":
            {
                return(await RedirectManufacturer(_webHelper.QueryString <string>("manufacturerid"), false));
            }

            case "producttag":
            {
                return(await RedirectProductTag(_webHelper.QueryString <string>("tagid"), false));
            }

            case "news":
            {
                return(await RedirectNewsItem(_webHelper.QueryString <string>("newsid"), false));
            }

            case "blog":
            {
                return(await RedirectBlogPost(_webHelper.QueryString <string>("blogpostid"), false));
            }

            case "topic":
            {
                return(await RedirectTopic(_webHelper.QueryString <string>("topicid"), false));
            }

            case "profile":
            {
                return(await RedirectUserProfile(_webHelper.QueryString <string>("UserId")));
            }

            case "compareproducts":
            {
                return(RedirectToRoutePermanent("CompareProducts"));
            }

            case "contactus":
            {
                return(RedirectToRoutePermanent("ContactUs"));
            }

            case "passwordrecovery":
            {
                return(RedirectToRoutePermanent("PasswordRecovery"));
            }

            case "login":
            {
                return(RedirectToRoutePermanent("Login"));
            }

            case "register":
            {
                return(RedirectToRoutePermanent("Register"));
            }

            case "newsarchive":
            {
                return(RedirectToRoutePermanent("NewsArchive"));
            }

            case "search":
            {
                return(RedirectToRoutePermanent("ProductSearch"));
            }

            case "sitemap":
            {
                return(RedirectToRoutePermanent("Sitemap"));
            }

            case "recentlyaddedproducts":
            {
                return(RedirectToRoutePermanent("NewProducts"));
            }

            case "shoppingcart":
            {
                return(RedirectToRoutePermanent("ShoppingCart"));
            }

            case "wishlist":
            {
                return(RedirectToRoutePermanent("Wishlist"));
            }

            case "CheckGiftCardBalance":
            {
                return(RedirectToRoutePermanent("CheckGiftCardBalance"));
            }

            default:
                break;
            }

            //no permanent redirect in this case
            return(RedirectToRoute("Homepage"));
        }
예제 #5
0
        public virtual IActionResult GeneralRedirect()
        {
            // use Request.RawUrl, for instance to parse out what was invoked
            // this regex will extract anything between a "/" and a ".aspx"
            Regex  regex        = new Regex(@"(?<=/).+(?=\.aspx)", RegexOptions.Compiled);
            string rawUrl       = _webHelper.GetRawUrl(this.HttpContext.Request);
            string aspxfileName = regex.Match(rawUrl).Value.ToLowerInvariant();

            switch (aspxfileName)
            {
            //URL without rewriting

            case "category":
            {
                return(RedirectCategory(_webHelper.QueryString <string>("categoryid"), false));
            }

            case "news":
            {
                return(RedirectNewsItem(_webHelper.QueryString <string>("newsid"), false));
            }

            case "blog":
            {
                return(RedirectBlogPost(_webHelper.QueryString <string>("blogpostid"), false));
            }

            case "topic":
            {
                return(RedirectTopic(_webHelper.QueryString <string>("topicid"), false));
            }

            case "contactus":
            {
                return(RedirectToRoutePermanent("ContactUs"));
            }

            case "passwordrecovery":
            {
                return(RedirectToRoutePermanent("PasswordRecovery"));
            }

            case "login":
            {
                return(RedirectToRoutePermanent("Login"));
            }

            case "register":
            {
                return(RedirectToRoutePermanent("Register"));
            }

            case "newsarchive":
            {
                return(RedirectToRoutePermanent("NewsArchive"));
            }

            default:
                break;
            }

            //no permanent redirect in this case
            return(RedirectToRoute("HomePage"));
        }
예제 #6
0
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="action">动作</param>
        /// <param name="data">数据</param>
        /// <param name="userId">用户编号</param>
        /// <param name="userName">用户名称</param>
        /// <param name="ip">IP</param>
        public async Task <bool> AddLogAsync(string action, string data, int userId, string userName)
        {
            var model = new LogEntity(action, webHelper.GetRawUrl(httpContextAccessor.HttpContext.Request), httpContextAccessor.HttpContext.Request.Method, data, userId, userName, webHelper.GetCurrentIpAddress());

            return(await this.AddAsync(model));
        }