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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Session variable in ASP.NET 1

Status
Not open for further replies.

fdarkness

Programmer
Feb 17, 2006
110
CA
Due to the way my server is set up, I have a session variable set to identify a user when they go onto the site (it's an internal only website).

In the global.asax page, I have:

Code:
Session["CISUserID"] = Request.Form["UserID"];

in the Session_Start method. It appears to work fine (tested it with an output statement).

Now I'm trying to call the session variable in a SELECT statement and I'm getting an error that says "CS0103: The name 'Session' does not exist in the current context". From what I read, this means that I haven't declared it, but I wasn't aware I needed to declare a Session variable. Is that the case? If so, where do I declare it?

The code that is causing the error is:
Code:
  comm.CommandText = "SELECT SystemUsers.UserID, SystemUsers.TeamID, NTLogon, " +
  "DevLogon, LastName, FirstName, Email, Transit, " +
  "SystemManagers.UserID, Manager, StartDate FROM SystemUsers, " +
  "SystemManagers WHERE SystemUsers.ManagerID = " +
  "SystemManagers.ManagerID AND NTLogon = " + Session["CISUserID"];

It's the last line that causes the error code to show up.
 
If you aren't on a Page, then you need to make a reference to the HttpContext.

So you'd say HttpContext.Current.Session["CISUserID"].ToString()

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top