views:

71

answers:

5

Is storing a list of 1000 instance of my custom class to the session variable a good approach ? My asp.net web app need multilingual support and i am storing the labels in a table.I will have multiple users who has their own language preference and text(label content) preference.

I am thinking about loading the labels and store it in session variable and access that to use in the pages.Storing it in Application variable does not work because each customer have their own text for the labels.So is storing session a good way of doing this ? I guess i will have almost 1000 labels as of now and it may increase as the application grows.

My custom class has 2 proprties. LanguageCode and LanguageName

for some reason i cant use asp.net Resource files :(

Whats your thoughts on this ?

+1  A: 

You should store a single set of labels for each language, then store the language name in session and use it to look up the correct labelset.

SLaks
SLaks, Thanks.But I m confused with "look up the correct label set" ? I am loading the list of my label class(LanguageCode,LangugeText) based on the users language preference.Do you mean to search in the session variable for the language text by saying "look up " ?
Shyju
You should maintain a single dictionary that maps LanguageCode to the label texts. You can then look up the set of label texts for the user's current language in the dictionary.
SLaks
Where should i store the dictionary? in session or application ?
Shyju
In a static field. (The dictionary should never change)
SLaks
+1  A: 

If I were you I'd first spend some time trying to figure out why your resource files are not working... as long as you are setting the Thread.CurrentThread.CurrentCulture (or is it CurrentUICulture?) value to the specific culture, and have the resource files in the correct place, I can't think of any reasons as to why it wouldn't work.

John
The manager does not want to use resource file for some reason.They want to manage the labels from tables.
Shyju
+1  A: 

Not a good idea, there are two problems with it:

  • It will use up the memory on the server, and reduce the number of users that can use the system
  • The time for each request will increase

The standard way to do this is using RESX (resource) files. You should try to fix that.

Shiraz Bhaiji
+1  A: 

Why not use Application variable and create as many Application variables as the languages you have. Each application variable will be a superset of all the labels for that language.
Or maybe store the entire table(s) in application variable(s), instead of storing multiple session variables that, I assume, they intersect with each other.

sh_kamalh
+1  A: 

Some thoughts to notice:

If your managers have something in particular against resx's, you can store all those labels in any other format (e.g. plain text files), or in a DB.

If you have little amount of users, and loading time is extremely crucial, your managers may have a point. Other than that, they're wrong, and I would consider trying to explain that to them.

Try considering "computing" the labels at runtime (e.g. if some of them include adding prefixes, suffixes, etc. you can save only the "stems" and provide a relevant label only on demand. That will save you some server space).

Oren A