LearnFast.Ninja

Check if session exists in C# .NET

In this tutorial you will see how to deal with session. It is very important to check if the session exists before you set its value, otherwise you can get an exception. What you should do is to check if the Session element exist, you doing this by checking if it is not null.

Example:

if (Session["UserName"] != null)

{

    Session["UserName"] = "string value";

}



Tags

asp.net

session session-exists null