if (!session["UserID"]==null && !session["UserName"]==null)
{
labelID.text= (string) Session["UserID"];
labelUserName.text= (string) Session["UserName"];
}
else
{
Response.Redirect("~/login.aspx");
}
using this, you are checking if user id and the user name are present in session if so then displaying the info on labels, if any of them doesnt exist, redirecting them to login.aspx.
in your log out code, dont rewrite the value of the sessional variables, instead drop them, use
Session.Clear();
to clear all the sessional values.