I handle the loading of user data in a single static class accessed by each of my aspx pages. I would like to add functionality to support Cookies and Session into this process. However, I am finding that the Response.Cookies object and the Session object are both unavailable to my util class.
Essentially, what I have now is (in it’s own file):
namespace myProject
{
static class myUtil
{
public static myProject.User LoadUser()
{
//Look up user
}
}
}
What I would like to do is:
namespace myProject
{
static class myUtil
{
public static myProject.User LoadUser()
{
if (Session['user'] != null)
{ user = Session['user']; }
else if (Response.Cookies['user'] != null)
{ user = Response.Cookies['user']; }
else
{
//Look up user
}
}
}
}
How can I make this happen? In the current implementation, all references to Session and Response.Cookies are seen as undeclared objects.
For reference, here are the current imports for the class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.Web.UI.Page;
using System.Web.UI.WebControls;
Session in class file
Cookies in class file