asp.net - Is it safe to use an HttpModule for localization? -
i'm considering making use of httpmodule localization purposes (based on example in this article) - i'm curious, safe?
here's code, reference:
public class cookielocalizationmodule : ihttpmodule { public void dispose() { } public void init(httpapplication context) { context.beginrequest += new eventhandler(context_beginrequest); } void context_beginrequest(object sender, eventargs e) { // eat cookie (if any) , set culture if (httpcontext.current.request.cookies["lang"] != null) { httpcookie cookie = httpcontext.current.request.cookies["lang"]; string lang = cookie.value; var culture = new system.globalization.cultureinfo(lang); // safe in situations? thread.currentthread.currentculture = culture; thread.currentthread.currentuiculture = culture; } } }
i under impression multiple threads potentially service web request. safe set current/current ui cultures in httpmodule , have respected life of web request regardless of how many threads involved in servicing it?
update:
i have been using method in production year now, can verify safe use httpmodule localization.
yes, should fine.
im pretty sure 1 thread service request, unless explicitly start another, , in case, culture (and other things) copied other thread.
Comments
Post a Comment