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!

[sadeyes] Having trouble with sessions

Status
Not open for further replies.

Jacqui1811

Programmer
Jul 8, 2002
100
SG
Hi Guys.
BTW if in the wrong area let me know I was not sure if it should be c# or .net area but as I am convinced it is the .net framework I am having trouble with rather than the syntax.
I have been doing asp for years fine and dandy but have now decided to try and move to asp.net.
I am trying to create a .cs file and assign an object to a session object.
When I try and compile the code using nant I get the following error "The name 'Session' does not exist in the class or namespace"
I realise that I am probabley doing something really stupid but I can not see what it is.
Here is the code for the method where I assign the game object to the variable and also my using directives so you can see what I am referencing:

using System ;
using BeadGame.Storage ;
using System.Collections ;
using System.IO ;
using System.Web ;
using System.Web.SessionState ;


// This will get the current game details
public static Game CurrentGame(IDataAccess sda)
{
string sqlStatement = "select game_ref from game where current = 'y' " ;

// execute the sql statement
IList GameIDs = sda.ExecSql(sqlStatement) ;

Hashtable ht = GameIDs[0] as Hashtable ;

int GameID = Convert.ToInt32(ht["game_ref"]) ;

GameDataManager dm = new GameDataManager() ;

IList ruleList = dm.GameRules(GameID);

Hashtable beads = dm.CurrentBeads(GameID) ;

Bag bag = new Bag(beads) ;

DateTime startDate = dm.GameStartDate(GameID) ;

Game myGame = new Game(GameID, ruleList, bag, startDate) ;

// Here we assign the current game object to the session game variable
Session[myGame] = myGame ;

return myGame ;

}// end

I am sure it is only me but I have even tried just assigning a string to the Session variable but get the same response.
Realy hope you can help, you normally do.
Thanks.
Jacqui
 
Is this a code behind class (doesn't look like one) or a regular class file? The session is only available from the page unless you inherit the page object in your class.

Vb

Public Class ClassName Inherits System.Web.UI.Page

Hope this helps.


Hope everyone is having a great day!

Thanks - Jennifer
 
You can access the ASP.NET session from any class in any assembly using

System.Web.HttpContext.Current.Session

Rob

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Hi.
Rob do I put the System.Web.HttpContext.Current.Session at the top of my page with a using ?
Jacqui.
 
You already have System.Web

HttpContext is a class not a namespace so don't put it at the top.


This should work
HttpContext.Current.Session["varName"] = var;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top