OwinMiddleware doesn't preserve culture change in .net 4.6.*

前端 未结 2 1785
北荒
北荒 2021-01-03 06:00

I have an owin culture middle ware running very nice.

It just changes the culture according to the url. This works in 4.5.* perfectly. Now when the runtiome is chang

相关标签:
2条回答
  • 2021-01-03 06:41

    I also tried to fix it with OwinMiddleware but failed.

    My solution was to create an ActionFilterAttribute and register this at startup:

    public partial class Startup : UmbracoDefaultOwinStartup
    {
        public override void Configuration(IAppBuilder app)
        {
            GlobalFilters.Filters.Add(new CultureCookieFilter());
            base.Configuration(app);   
        }
    }
    
    public class CultureCookieFilter : ActionFilterAttribute
    {
        private const string CULTURE_KEY = "X-Culture";
    
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.Request.Cookies[CULTURE_KEY] != null)
            {
                var langCookie = filterContext.HttpContext.Request.Cookies[CULTURE_KEY];
                if (langCookie != null)
                {
                    var lang = langCookie.Value;
                    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang);
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
                }
            }
    
            base.OnActionExecuting(filterContext);
        }
    }
    
    0 讨论(0)
  • 2021-01-03 06:42

    I got a response from microsoft which works for me.

    you can try set the following element in your web.config file. This element has to be child to the <appSettings> element.

    <add key="appContext.SetSwitch:Switch.System.Globalization.NoAsyncCurrentCulture" value="true" />
    
    0 讨论(0)
提交回复
热议问题