Why can't I read session variables

Posted by Marty Goetz on Stack Overflow See other posts from Stack Overflow or by Marty Goetz
Published on 2012-10-27T16:57:29Z Indexed on 2012/10/27 17:00 UTC
Read the original article Hit count: 211

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET