Using Static classes to maintain state between ASP.Net pages

Unusually enough, one of my colleagues, used a static class to maintain state between post backs in an ASP.Net page. Basically he stored the list of values to be populated in a dropdown list in a static class. First time when the page was loaded this list would be populated from the database and the next time onwards, the list will be populated back from a static class. This worked perfectly fine in the development and QA environments. But when the code was deployed in the production environment which had a web farm(with clustered and load-balanced web servers), the list wasn't getting populated consistantly. The order of values in the list was changing. After spending time in debugging, we identified this as the route cause. The issue was sorted out after the list was retained in a session variable. I think that using Static classes for maintaining the state is not a good practice, even if we have to, I think we should avoid that in web farm environment.

Comments

Popular posts from this blog

Crystal Reports - Drill down web reports in a new window

Why TechGiggles?