Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sessions is Class file

Status
Not open for further replies.

phaseshift

IS-IT--Management
Dec 13, 2004
45
US
The following is an example of code that is not working. I am trying to write a class file that will set session variables as needed.

public static string ID
{
get
{
return HttpContext.Current.Session["ID"].ToString();
}

set
{
HttpContext.Current.Session["ID"] = value;
}
}

any ideas on how to get sessions to work with gets and sets?

thanks
 
HttpContext.Current.Session.Keys.Add("ID", value);

Does that work?
 
There is not a Key.Add avaliable.
I tried: HttpContext.Current.Session.Keys[0] = value;

and that didn't work either.

Thanks again
 
I can't find anythin like addkey.

The problem seems to be because I am not adding the session to an aspx.cs file. If I try and add a session to a ascx.cs file(a custom control) I can't access the session vairable when I get back to the page code.

any thoughts
 
I have a login control that returns your id and access level upon a valid login. I need to store these values in a session for later use.

Whoever wrote the org. code used Cache which is not creating a problem since cache is shared with everyone accessing the server.

 
I understand now.

I'm assuming you're accessing a database that you can write to? You might want to consider doing all of your permissions on the server side.

Store the given SessionID in the database with the associated permissions level. When you make a server request, try pulling the permissions from the database using their SessionID. This allows you to hide the Username/Password and manage all permissions on the server side. This is much safer.

Your calls could then be something similar to:



IF you still need to add session keys, check out this link

 
Another vote for storing session in the database.

When you add a second web server via MS network load balancing or a hardware load balancer (preferred), you need to handle the case where a returning user gets directed to the other server. If the session is stored on one server, it won't be available to the others in the web farm.

While MS NLB says it handles this, a friend's experience has been that NLB is more prone to blue-screening, thus the recommendation of a hardware load balancer.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top