c# - Set CultureInfo in Asp.net Core to have a . as CurrencyDecimalSeparator instead of , -


i'm going mad. want culture used in entire asp.net core application set "en-us". nothing seems work. set culture entire application? i'm not interested in client browser cultures , not. thing seems change changing language settings of windows. want culture determined within application itself, not client.

what have tried far:

  • set <system.web><globalization uiculture="en" culture="en-us" /></system.web> in web.config
  • set system.threading.thread.currentthread.currentculture = cultureinfo; , currentuiculture in startup.configure , in controller.
  • use app.userequestlocalization(.. shown below

        var enusculture = new cultureinfo("en-us");     var localizationoptions = new requestlocalizationoptions()     {         supportedcultures = new list<cultureinfo>()         {             enusculture         },         supporteduicultures = new list<cultureinfo>()         {             enusculture         },         defaultrequestculture = new requestculture(enusculture),         fallbacktoparentcultures = false,         fallbacktoparentuicultures = false,         requestcultureproviders = null     };      app.userequestlocalization(localizationoptions); 

but nothing seems change currencydecimalseparator (nl-nl) , (en-us).

how can culture set?

edit: @soren how configure method looks like. i've put breakpoint on determineprovidercultureresult never hit while visiting website.

public void configure(iapplicationbuilder app, ihostingenvironment env, iloggerfactory loggerfactory, finosdbcontext context)     {         loggerfactory.addconsole(configuration.getsection("logging"));         loggerfactory.adddebug();          if (env.isdevelopment())         {             app.usedeveloperexceptionpage();             app.usedatabaseerrorpage();             app.usebrowserlink();         }         else         {             app.useexceptionhandler("/home/error");         }          app.usestaticfiles();          app.useidentity();          // add external authentication middleware below. configure them please see http://go.microsoft.com/fwlink/?linkid=532715          app.usemvc(routes =>         {             routes.maproute(                 name: "default",                 template: "{controller=home}/{action=index}/{id?}");         });          //todo: clean         //var cultureinfo = new cultureinfo("en-us");         //system.threading.thread.currentthread.currentculture = cultureinfo;         //system.threading.thread.currentthread.currentuiculture = cultureinfo;          app.userequestlocalization();          // usecookieauthentication..         // usejwtbearerauthentication..          //add userculture provider authenticated user         var requestopt = new requestlocalizationoptions();         requestopt.supportedcultures = new list<cultureinfo>         {             new cultureinfo("en-us")         };         requestopt.supporteduicultures = new list<cultureinfo>         {             new cultureinfo("en-us")         };         requestopt.requestcultureproviders.clear();         requestopt.requestcultureproviders.add(new singlecultureprovider());         app.userequestlocalization(requestopt);          app.userequestlocalization(requestopt);           finosdbcontext.initialize(context);         finosdbcontext.createtestdata(context);     }      public class singlecultureprovider : irequestcultureprovider     {         public task<providercultureresult> determineprovidercultureresult(httpcontext httpcontext)         {             return task.run(() => new providercultureresult("en-us", "en-us"));         }     } 

this solves me:

setting following in startup.configure

        var cultureinfo = new cultureinfo("en-us");         cultureinfo.numberformat.currencysymbol = "€";          cultureinfo.defaultthreadcurrentculture = cultureinfo;         cultureinfo.defaultthreadcurrentuiculture = cultureinfo; 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -