c# - ModelState Errors always showing in English in Azure Web Role -
i´m having problems model validation errors in asp.net webapi deployed in azure.
this code returns modelstate errors:
public static class comprobarerroresmodelo { public static string geterrors(modelstatedictionary modelstate) { var result = ""; foreach (var error in modelstate.values.selectmany(value => value.errors)) if (string.isnullorempty(error.errormessage)) result = result + error.exception.message + '\n'; else result = result + error.errormessage + '\n'; return result; } }
in global.asax have tried several modifications on this:
protected void application_acquirerequeststate(object sender, eventargs e) { thread.currentthread.currentuiculture = new cultureinfo("es"); thread.currentthread.currentculture = new cultureinfo("es"); cultureinfo.defaultthreadcurrentculture = new cultureinfo("es"); cultureinfo.defaultthreadcurrentuiculture = new cultureinfo("es"); } void application_beginrequest(object sender, eventargs e) { thread.currentthread.currentuiculture = new cultureinfo("es"); thread.currentthread.currentculture = new cultureinfo("es"); cultureinfo.defaultthreadcurrentculture = new cultureinfo("es"); cultureinfo.defaultthreadcurrentuiculture = new cultureinfo("es"); }
but none of them works in azure, modelstate errors in english
i have tested in local environment changing "es" "en" , works ok, in azure shows english message errors
how can modelstate errors in spanish or other language in azure web role??
you can create basecontroller
, has culture set while it's initialized, , make api controllers inherit instead of apicontroller
directly:
public abstract class basecontroller : apicontroller { protected override void initialize(httpcontrollercontext requestcontext) { base.initialize(requestcontext); var culture = new cultureinfo("es"); system.threading.thread.currentthread.currentculture = culture; system.threading.thread.currentthread.currentuiculture = culture; } }
Comments
Post a Comment