session variable giving 'Object reference not set to an instance of an object' error

J

JC

Hi,

Thanks for reading...

I am authenticating users in a web app thus:

sqlCommand2.Parameters["@username"].Value = txtUserName.Text;
sqlConnection1.Open();
string userEmail = (string)sqlCommand2.ExecuteScalar();
sqlConnection1.Close();
Session.Add("userEmail",userEmail);
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(txtUserName.Text,false);

The variable userEmail is being populated. However, when I later on
try to retrieve the session variable 'userEmail' using...

Response.Write(Session["userEmail"].ToString());

I get 'Object reference not set to an instance of an object' error.
Clearly I'm missing something - your advice would be appreciated.
Perhaps there is a better way to persist this information? Thanks for
your help.
 
M

Morten Wennevik

In your Global.asax file, try setting Session["userEmail"] = "";
under Session_Start
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top