Session Data Problem

Hi there,

I have a website, when someone logs in, I create a Session variable for the id of the person who logged in. When they logout, I run these lines of code:

FormsAuthentication.SignOut();
Response.Cookies.Clear();
Session.Clear();
Session.RemoveAll();
Context.Application.RemoveAll();

And when I log in as another user, the session variable does something weird. It logs in and the Session variable gets created, but when I run  this code on  my Navigation.ascx control:
<%
                if (Session["EmpId"].ToString().Equals("10002"))
                {
                    Response.Write("<b><a href='AdminPage.aspx'>Task Setup Page</a></b><br><br><br>");
                }
%>

It doesn't catch that id, even though I logged in as EmpId 10002.

Anyone have any idea on why this is happening or how I can fix this?
LVL 3
quanmacAsked:
Who is Participating?
 
samtran0331Commented:
if you do:
Response.Write(Session["EmpId"].ToString());

what does it return?

have you tried doing:
if (Session["EmpId"].ToString == "10002")
instead of:
if (Session["EmpId"].ToString().Equals("10002"))
0
 
sabeeshCommented:
Are you setting up the Session["EmpId"].= "10002" after successfully log in to the system?
0
 
quanmacAuthor Commented:
Yes, after the person logs in, they get forwarded to their profile page, and the page reads the Session["EmpId"] value
0
 
quanmacAuthor Commented:
if (Session["EmpId"].ToString == "10002")

That Worked
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.