Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC Localication set culture in httpmodule
    text
    copied!<p>I have implemented Localization on my MVC3 Application.</p> <p>i am looking for a solution to setup the current culture before the ActionFilterAttribute is executed.</p> <p>i would like to get the the current culture from the url:</p> <pre><code>routes.MapRoute( "Language", "{culture}/{controller}/{action}/{id}", new { culture = "en", controller = "Page", action = "Index", id = UrlParameter.Optional } ); </code></pre> <p>in the base controller i can do:</p> <pre><code>protected override void OnActionExecuting(ActionExecutingContext filterContext) { var culture = filterContext.RouteData.Values["culture"] ?? ConfigurationSettings.AppSettings["DefaultCulture"]; var cultureInfo = CultureInfo.GetCultureInfo((string)culture); Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; base.OnActionExecuting(filterContext); } </code></pre> <p>i would like to update the application and setup the current culture in the httpmodule</p> <p>at the moment my code looks like this:</p> <pre><code>public void Init(HttpApplication httpApplication) { httpApplication.BeginRequest += (sender, eventArgs) =&gt; { var defaultCulture = ConfigurationSettings.AppSettings["DefaultCulture"]; CultureInfo cultureInfo = CultureInfo.GetCultureInfo(defaultCulture); try { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; } catch { } }; } </code></pre> <p>how can i setup the current culture using the filterContext.RouteData.Values["culture"] in the httpmodule ?</p> <p>Thank you in advanced for any help</p> <p>Ori</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload