Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Getting values from session in C#

The below example shows how to retrieve the value from the session through its id.
  1. //Storing UserName in Session
  2. Session["UserName"] = txtUser.Text;


  1. //Check weather session variable null or not
  2. if (Session["UserName"] != null)
  3. {
  4. //Retrieving UserName from Session
  5. lblWelcome.Text = "Welcome : " + Session["UserName"];
  6. }
  7. else
  8. {
  9. //Do Something else
  10. }