9

This might be a silly question with an easy answer, but I cannot seem to find any info on it.

I am creating a webapp for a clients intrant, and I am using session variables, which start as they log in.

EG:

Session["ConsultantFirstname"] = adAuth.getFirstName();
Session["ConsultantLastName"] = adAuth.getLastName();

//Then I also have a reader on page load which creates these...

while (reader.Read())
{
    Session["Department"] = reader[1].ToString();
    Session["Channelid"] = reader[2].ToString();
    Session["EmailAddress"] = reader[3].ToString();
    Session["PrimaryTerritory"] = reader[4].ToString();
}

My question is this... How do I see in the browser what session variables have been created? (If I select "Inspect element" > "Resources" > Session storage.. Shouldn't they be there?) I'm quite sure I read a tutorial on this a while ago, but I cannot seem to find it now.

enter image description here

Do I need to add some additional code?

user229044
  • 232,980
  • 40
  • 330
  • 338
Fizor
  • 1,480
  • 1
  • 16
  • 31
  • 2
    There are 2 different things called "Session Storage". One is the server session, which is not visible to the browser. The other is the browser Session Storage, which is a set of name/value pairs that exist only on the browser. Your inspect window screen shot is showing the browser session storage, but you are asking about the server session storage. – DaveInMaine May 24 '20 at 20:40

2 Answers2

9

You cannot view the session state variable at client side. Session state is stored at server, and Client browser only knows SessionID which is stored in cookie or URL.

MSDN says:

Sessions are identified by a unique identifier that can be read by using the SessionID property. When session state is enabled for an ASP.NET application, each request for a page in the application is examined for a SessionID value sent from the browser. If no SessionID value is supplied, ASP.NET starts a new session and the SessionID value for that session is sent to the browser with the response.

By default, SessionID values are stored in a cookie. However, you can also configure the application to store SessionID values in the URL for a "cookieless" session.

Google Chrome provides some extension through which you can edit the cookies.

Community
  • 1
  • 1
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • 2
    Hmmm, guess ill just have to add them to a cookie for now. Only reason I want to see them now is to make sure that the correct sessions are up and running for while they are going from page to page etc. Thanks for confirming! – Fizor Apr 16 '14 at 07:36
  • Any reason that you don't do client side logging or general output of the values instead? I would assume that you don't want to deploy with visible session variables. I only suggest this because with using a cookie is that you may forget to remove it in production; if it is immediately apparent on the page it is hard to miss. You could also use local storage which was new with HTML 5, whereas you can store up to 10 MB of data on a client machine. – Anthony Mason Jun 22 '16 at 13:15
1

try to put print_r($_SESSION); in your code this will print content of $_SESSION variable at that moment.

Medo
  • 21
  • 2
  • 1
    You should probably point out the language in which you are using, although obvious to those familiar with PHP would recognize it (I hope anyway :-/). With ASP.NET, <% Session["key"] %> or @Session["key"] depending on the syntax you are using is how you would access the variables. Not saying you are wrong in your answer of course. The tags show ASP.NET, C#, so that should be addressed first and foremost but I won't down vote as it is a good answer for people other than OP. – Anthony Mason Jun 22 '16 at 13:21