public ActionResult ChangeLanguage(string lang) { LanguageManagement.SetCurrentLanguage(lang); System.Web.HttpContext.Current.Application["CurrentLanguage"] = lang.Equals("vi") ? "Vietnamese" : "English"; return(RedirectToAction("Index", "AdminHome")); }
protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state) { string lang = null; HttpCookie langCookie = Request.Cookies["culture"]; if (langCookie != null) { lang = langCookie.Value; } else { var userLanguage = Request.UserLanguages; var userLang = userLanguage != null ? userLanguage[0] : ""; if (userLang != "") { lang = userLang; } else { lang = LanguageManagement.GetDefaultLanguage(); } } LanguageManagement.SetCurrentLanguage(lang); return(base.BeginExecuteCore(callback, state)); }
/// <summary> /// Creates an action invoker. /// </summary> /// <returns>An action invoker.</returns> protected override IActionInvoker CreateActionInvoker() { LanguageManagement langman = new LanguageManagement(this.SessionCustom, HttpContext); //this.CurrentLanguage = langman.GetLanguage(Thread.CurrentThread.CurrentCulture.Name); UpdateLanguage(); if (HttpContext.User.Identity.IsAuthenticated) { string cookieName = FormsAuthentication.FormsCookieName; HttpCookie authCookie = HttpContext.Request.Cookies[cookieName]; FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); string[] data = authTicket.UserData.Split('|'); FormsIdentity id = new FormsIdentity(authTicket); HttpContext.User = this.CustomUser = new CustomPrincipal(id, data); } else { HttpContext.User = this.CustomUser = new CustomPrincipal(HttpContext.User.Identity); } return(base.CreateActionInvoker()); }
/// <summary> /// Creates the specified controller by using the specified request context. /// </summary> /// <param name="requestContext">The context of the HTTP request, which includes the HTTP context and route data</param> /// <param name="controllerName">The name of the controller.</param> /// <returns>The controller</returns> public override IController CreateController(RequestContext requestContext, string controllerName) { Type controllerType = this.GetControllerType(requestContext, controllerName); IController controller; Language language = null; ISession session = MvcApplication.Container.Resolve <ISession>(); LanguageManagement langrepo = new LanguageManagement(session, requestContext.HttpContext); if (requestContext.RouteData.Values.ContainsKey("culture")) { if (requestContext.RouteData.Values["culture"].ToString().ToLower() == "vs") { HttpContext.Current.Response.Cookies.Add(new HttpCookie("vs", "true")); } language = langrepo.GetLanguage(requestContext.RouteData.Values["culture"].ToString()); } else { language = langrepo.GetLanguageDefault(); } Thread.CurrentThread.CurrentCulture = new CultureInfo(language.Culturename); Thread.CurrentThread.CurrentUICulture = new CultureInfo(language.Culturename); if (controllerType != null) { controller = this.GetControllerInstance(requestContext, controllerType); } else { FriendlyurlRepository friendly = new FriendlyurlRepository(session); friendly.Entity.LanguageId = language.LanguageId; friendly.Entity.Friendlyurlid = requestContext.RouteData.Values["controller"].ToString(); friendly.LoadByKey(); if (friendly.Entity.Id != null) { string queryString = this.CreateQueryString(HttpContext.Current.Request.QueryString); if (friendly.Entity.Type == Friendlyurl.FriendlyType.Content) { HttpContext.Current.RewritePath("~/Contenido/Index/" + friendly.Entity.Id + "?lang=" + language.LanguageId + queryString); controllerType = this.GetControllerType(requestContext, "Contenido"); } else if (friendly.Entity.Type == Friendlyurl.FriendlyType.Idea) { HttpContext.Current.RewritePath("~/Idea/Index/" + friendly.Entity.Id + "?lang=" + language.LanguageId + queryString); controllerType = this.GetControllerType(requestContext, "Idea"); } else if (friendly.Entity.Type == Friendlyurl.FriendlyType.BlogEntry) { HttpContext.Current.RewritePath("~/Blog/Index/" + friendly.Entity.Id + "?lang=" + language.LanguageId + queryString); controllerType = this.GetControllerType(requestContext, "Blog"); } else if (friendly.Entity.Type == Friendlyurl.FriendlyType.Section) { HttpContext.Current.RewritePath("~/Seccion/Index/" + friendly.Entity.Id + "?lang=" + language.LanguageId + queryString); controllerType = this.GetControllerType(requestContext, "Seccion"); } else if (friendly.Entity.Type == Friendlyurl.FriendlyType.SuccessCase) { HttpContext.Current.RewritePath("~/SuccessCase/Index/" + friendly.Entity.Id + "?lang=" + language.LanguageId + queryString); controllerType = this.GetControllerType(requestContext, "SuccessCase"); } RouteData routeData = RouteTable.Routes.GetRouteData(requestContext.HttpContext); foreach (KeyValuePair <string, object> routeElement in routeData.Values) { requestContext.RouteData.Values[routeElement.Key] = routeElement.Value; } } else { throw new HttpException(404, string.Empty); } if (session != null) { session.Dispose(); } controller = this.GetControllerInstance(requestContext, controllerType); } return(controller); }
public ActionResult ChangeLanguage(string language) { LanguageManagement.SetCurrentLanguage(language); return(RedirectToAction("Index", "Home")); }