You need to check if the Session variable exists before you can use it and assign it to it.
You can increment as follows.
Session["PagesViewed"] = ((int) Session["PagesViewed"]) + 1;
But if Session["PagesViewed"] does not exist, it will cause errors. A quick null test before incrementing should sort it.
if (Session["PagesViewed"] != null) Session["PagesViewed"] = ((int)Session["PagesViewed"]) + 1;
source share