Problem solve Get help with specific problems with your technologies, process and projects.

Accessing session variables in different pages

How do you access session variables in different pages of an application?

For example: I have Session("USerId") = "ABC" in page1.aspx. I go to Page2.aspx on clicking a button in page1. Can I use like this Dim sUser as string:
sUser = Session("UserId") in page2.aspx?

You just use them and it just works. Are you having any problem with the code you sent? By the way, you have to enable session state in the web config in order for that to work (<sessionState mode="anything but OFF"). Recall that depending on your server configuration you may need to select different values. If you have a Web Farm, InProc will only work on a single machine, and you have to ensure following requests coming from the same user are redirected to the same server that answered the first time (LocalDirector from Cisco is a well-known product for that). Otherwise, you have to either select StateServer or SQLServer to persist the session information in a central location. You can find a lot more about this and other fundamental concepts in ASP.NET in a book such as this one.

Dig Deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.