overview
we have multinational website has localised content various countries serves. localisation implemented using standard .net resource files.
when our web application starts or recycles under load on production environment, display wrong resources particular country. e.g. uk site may show french content.
this continues happen until application restarted.
detail
the production environment iis 8 on windows server 2012. application implemented in asp.net mvc 4.
the application decides locale serving incoming url. www.mysite.com uk english www.mysite.fr french etc.
we have implementation of ihttpmodule registered via web.config. in init method of module, attaches handler beginrequest event. in method, incoming url examined , thread's currentuiculture set appropriate value. en-gb www.mysite.com, fr-fr www.mysite.fr etc.
this system works part. however, when application starts while receiving requests, consistently serve wrong content of resource files.
it continues until application restarted. may again restart serving incorrect content. have keep restarting until serving correct content, @ point remain stable.
analysis
we have been able reproduce locally on development pc throwing requests @ application during startup (using fiddler). site showing german content resource files on uk version of site.
having checked obvious culprits in our code (that currentuiculture set correctly http module , remains correct throughout processing of request), started @ resource manager.
with application started in incorrect state, examined contents of _resourcesets property on resourcemanager class. dictionary keyed on iso culture code. examining contents of en-gb, found did contain resource strings german version of resource file.
it seems sometimes, when site starting while receiving requests, resourcemanager class loading wrong resource file culture or incorrectly classifying file in dictionary.
has else experienced kind of behavior , aware of workarounds?
thanks.
this sounds having thread safety problems in handler. when modify threads current culture, modifying current thread processing multiple requests. when responses generated, request have altered thread current language giving responses same language.
i have few suggestions can start off with:
- make sure handler not reusable. assume you've made implemented ihttphandler, return false isreusable property since multiple threads should hit @ same time , new instance created per request.
- don't use handler... handler not ideal solution this, preferred place set thread culture in application_acquirerequeststate correctly fired each request without overlapping.
- use routing handler instead: http://adamyan.blogspot.com/2010/07/addition-to-aspnet-mvc-localization.html
without seeing handler speak of rest can speculation why responses sharing thread cultures. problem lie in dictionary using inherently not thread safe.
Comments
Post a Comment