Forum Moderators: open

Message Too Old, No Replies

Problem with Session Var

         

IntegrityWebDev

8:54 pm on Sep 23, 2010 (gmt 0)

10+ Year Member



I have the following code in "functions.cs" in the App_Code folder:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;

public class MyFunctions
{
public static void SetSession()
{
//if IsLoggedIn Session Var doesn't exist, create it
if (Session["IsLoggedIn"] == null)
{
Session["IsLoggedIn"] = "no";
}
}
...


And it dies here:
if (Session["IsLoggedIn"] == null)

With this error:
The name 'Session' does not exist in the current context

Any thoughts?

mattglet

11:21 pm on Sep 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do this:

if (HttpContext.Current.Session["IsLoggedIn"] == null)

MyFunctions doesn't derive from the Page class (where Session is used), so you need to fully qualify the Session object.

IntegrityWebDev

12:46 pm on Sep 24, 2010 (gmt 0)

10+ Year Member



That got it. :-)