Why can't I read session variables
- by Marty Goetz
I have a c# .net web application. I create session variables but when I try to read them after I leave the page that they were created from I can't.
Created on page 1
Session["UserName"] = "WhatEver";
Then I do
Response.Redirect("~/whatever.aspx");
and try to read to read the session variable in the Page_Load method of the new page
string userName = Session["UserName"].ToString();
I receive "Object reference not set to an instance of an object." Why am I receiving this error and what can I do to fix the problem?
I would greatly appreciate any help anyone can give me.