views:

45

answers:

3

Hi,

My website uses a web user control. The properties for the user control will be set will be common for a set of my users. e.g. if I have 20 users accessing my website, 5 of them may be using the user control with id = 1 , 4 using the user control with id =2. I have a property associated with each user control which I would like to be shared between users accessing a common id.

I thought of the following:

  • Applicaton variable which saves a id / proprty value array combination
  • Creating static properties for the user control, however i feel that the value will be shaed between all the users irrespective of the id.
  • Or store it in the database [i want to reduce interaction with the database.]

Please advice.

A: 

If you're determined not to use a database, bear in mind that if your application scales out to multiple servers you may need to revisit your architecture at that point otherwise your control may end up displaying different information on different servers for the same id.

If you're happy with that, then you might want to think about storing your information in the ASP.NET cache e.g.

System.Web.Caching.Cache cache = Page.Cache;

List<KeyValuePair<string, object>> controlSetup;

controlSetup = cache.Get("ControlSetup" + this.Id.ToString());

if (controlSetup == null)
{
    // Create the control setup from scratch
    // Put the created control setup into the cache
    cache.Put("ControlSetup" + this.Id.ToString(), controlSetup);
}

foreach (KeyValuePair(string, object) item In controlSetup
{
    // Set the control values
}
PhilPursglove
A: 

Not sure if I understand you correctly; assuming that you want to show/hide certain item based upon the id.

If thats so, then how about:

You provide a switch case in your control upon load; that checks for the id and set the visibility of the item that you want to be shared.

Say, for instance, id is the user role. So based upon that, I would:

switch (nRoleID)
{ 
    case 1: //Set controls visibility and hide others/
        break;
    case 2: //Do something.
        break; ;
    default: //Hide all
        break;
}

Just thinking out loud.

KMan
A: 

Remember HTTP is stateless, so your first 2 options wont work.

The best alternative is to store the information thats common for multiple users is DB.

Cheers

Ramesh Vel