Get Value from Session Variable in C#

It’s common practice to store certain values in session variables to allow for easy access of data between page loads. This is known as a Server Variable in C#. Assume a server variable name of “foo“. It would be accessed as:

string myValue = Request.ServerVariables.Get("foo");

If you get the following error message: The name “Request” does not exist in the current context, try the following:

string myValue = System.Web.HttpContext.Current.Request.ServerVariables.Get("foo");
Share and Enjoy:
  • Digg
  • DotNetKicks
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Live
  • MySpace
  • Netvibes
  • Reddit
  • StumbleUpon
You can leave a response, or trackback from your own site.

2 Responses to “Get Value from Session Variable in C#”

  1. Jim Gannon says:

    The above is a good for a server variable. I am looking to have a second project run by clicking a button on a form. I am stuck and can’t seem to find an information for this…I have the projects already to go I want to
    run the second project from the first using a button click..any thoughts would be greatly appreciated

    Thanks
    jmg

  2. i want to retrieve a data through a session

Leave a Reply