How to retrieve values from Session Variables?

 Posted by vishalneeraj-24503 on 12/23/2013 | Category: ASP.NET Interview questions | Views: 786 | Points: 40
Answer:

It's easy to retrieve values from Session Variables.
Note:-Always check Null before retrieving values from Session otherwise exception occurs.

For Example:-
In C#,

string name = string.Empty;

if (Session["Name"] != null)
{
name = Convert.ToString(Session["Name"]);
}


In VB.Net,

Dim name As String = String.Empty

If (Not Session("Name") Is Nothing) Then
name = Convert.ToString(Session("Name"))
End If


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response