/// <summary>
        ///
        /// </summary>
        public static string GetCurrentLanguage(this RouteData routeData)
        {
            var value = routeData.Values[MvcUrlExtension.LanguageRouteKey] as string;

            if (string.IsNullOrWhiteSpace(value))
            {
                return(MvcUrlExtension.GetCultureTwoDigit());
            }
            return(value);
        }
示例#2
0
 /// <summary>
 ///
 /// </summary>
 public RedirectToLozalizedRoute(bool useCurrentCultureLangauge, string defaultLanguage)
     : base(ControllerActionId, new MvcRouteHandler())
 {
     _useCurrentCultureLangauge = useCurrentCultureLangauge;
     _defaultLanguage           = defaultLanguage;
     if (string.IsNullOrWhiteSpace(_defaultLanguage))
     {
         _defaultLanguage = MvcUrlExtension.GetCultureTwoDigit();
     }
     Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = UrlParameter.Optional });
 }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var data = base.GetRouteData(httpContext);

            if (data == null)
            {
                return(null);
            }

            var lang = data.Values[MvcUrlExtension.LanguageRouteKey];

            if (lang == null)
            {
                string language = _defaultLanguage;
                if (_useCurrentCultureLangauge)
                {
                    language = MvcUrlExtension.GetCultureTwoDigit(language);
                }
                data.Values[MvcUrlExtension.LanguageRouteKey] = language;

                RedirectToLocalizedLocation(httpContext, language);
            }
            return(data);
        }