コード例 #1
0
        /// <summary>
        /// Returns information about the requested route.
        /// </summary>
        /// <param name="httpContext">An object that encapsulates information about the HTTP request.</param>
        /// <returns>
        /// An object that contains the values from the route definition.
        /// </returns>
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            if (this.SeoFriendlyUrlsForLanguagesEnabled)
            {
                var helper = new LocalizedUrlHelper(httpContext.Request);
                if (helper.IsLocalizedUrl())
                {
                    helper.StripSeoCode();
                    httpContext.RewritePath("~/" + helper.RelativePath, true);
                }
            }

            if (_leftPart == null)
            {
                var url = this.Url;
                int idx = url.IndexOf('{');
                _leftPart = "~/" + (idx >= 0 ? url.Substring(0, idx) : url).TrimEnd('/');
            }

            // Perf
            if (!httpContext.Request.AppRelativeCurrentExecutionFilePath.StartsWith(_leftPart, true, CultureInfo.InvariantCulture))
            {
                return(null);
            }

            RouteData data = base.GetRouteData(httpContext);

            return(data);
        }
コード例 #2
0
        /// <summary>
        /// Returns information about the URL that is associated with the route.
        /// </summary>
        /// <param name="requestContext">An object that encapsulates information about the requested route.</param>
        /// <param name="values">An object that contains the parameters for a route.</param>
        /// <returns>
        /// An object that contains information about the URL that is associated with the route.
        /// </returns>
        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            VirtualPathData data = base.GetVirtualPath(requestContext, values);

            if (data != null && this.SeoFriendlyUrlsForLanguagesEnabled)
            {
                var    helper = new LocalizedUrlHelper(requestContext.HttpContext.Request, true);
                string cultureCode;
                if (helper.IsLocalizedUrl(out cultureCode))
                {
                    if (!requestContext.RouteData.Values.ContainsKey("StripInvalidSeoCode"))
                    {
                        data.VirtualPath = String.Concat(cultureCode, "/", data.VirtualPath);
                    }
                }
            }
            return(data);
        }