views:

314

answers:

5

I'm building a web system and various clients will have alternate text for default instances throughout the site. One place is the main nav but there are others. The default may be "project" but they may want to call it "event".

I'm heading down the road of calling all the terminology settings (there's a list of about 15) and creating an ArrayList that has the id and either the default or their replacement as the items in the ArrayList.

I've also got a enum key list called TermKey that has the defaults and the corresponding ID number.

Throughout the code I'll reference TermKey.Project and then do one of these things that I see as options. 1-pull the text from the session (if the client has set it to "event" then the text "event" will be waiting for the call there) 2-pull the text from the database every time I need it. 3-pull the client's list each time a page loads.

Some thoughts on the impact each way or if there is a best practice for this sort of thing would be appreciated.

A: 

If this is specific to each user, you might as well use session. Don't overuse is (and only use it for small amounts of data).

Going to the database for each request can be overkill, especially if this data doesn't change often - it will be much faster to retrieve from local memory than from over the network.

Having said that, using session InProc will limit you to a single server and will not allow you to scale to a web farm.

Oded
thanks. If I end up needing a farm I'll have quite a bit more revenue to devote to specifics. The thought is provoking though.
tnriverfish
+1  A: 

Anyway you shouldn't call DB on every page just to get alternate text. I think it is fine to store them in session if there are not too many of them (per user)

Andrey
thanks. I'm going with session for now I believe. It is a low volume site and probably will be for a while.
tnriverfish
+1  A: 

The way I've done this in the past is to have a database type code table and then a client-specific translation table like this:

TABLE ObjectType
ObjectTypeCode

TABLE ClientObjectTypeTranslation
ClientId
ObjectTypeCode
OverrideDescription

This allows my code to always reference what I know (i.e. ObjectTypeCode) and I then join to the translation table on every query and display the override description where relevant.

Though, this may be overkill for your scenario.

Jacob G
I think I see what you're saying but it sounds like you're creating the table in memory which seems similar to holding it in session. am I wrong or not understanding what you've said?
tnriverfish
Not necessarily... This would be in the database. Let's say that you have an object called Foo. Client A calls it Bar, Client B calls it Baz and Client C has no override. When the user clicks "View" on a particular object, you retrieve the details from the DB joined to the TypeTranslationTable so that you know, in the screen you're building, to have a particular label say Foo, Bar or Baz based on the client. I do this a bunch for Status Codes where clients want different names for essentially the same status.
Jacob G
+1  A: 

The session isn't the best place for this kind of information. While yes, it is user-bound, the session state is really a repository for user-bound, session-bound information. What you seem to have is information that really has a scope beyond session.

The best way to reflect this information is to use a custom ASP.NET Profile Provider. You would use it to expose properties for the information you need to expose, while the logic in the properties would handle setting the values to the appropriate values based on the user in your system (or, an anonymous user, if they are not authenticated).

In your case, you could cache the values and access the database as needed in the profile provider.

Then, this information is exposed through the Profile property on the HttpContext class (and through the Profile property on the HttpProfileBase class as well if you are using ASP.NET MVC).

casperOne
woa. hadn't heard of the Profile Provider before. Sounds like a situation where I'll build with intent to implement if the system takes off. Looks like you start up a separate profile db and point the Profile Provider to it. I don't expect to have that many users connected to cause trouble with session stuff but I'll be building so that I can swap out to point my info repository to live in the separate db later.
tnriverfish
+1  A: 

Session is ok to do this if you want to persist across sessions (and it's not TOO much data). Another option would be cookies. I'd recommend on session start, instantiate session vars in a User object property, then can reference, User.DefaultText

pjacko
that's what I've got! thanks. Since it is used in aspects so regularly like the main nav then I thought cookies might have a negative impact due to trying to access them so often.
tnriverfish