Error when ussing session

Posted by Mongz under C# on 9/23/2009 | Views : 1069 | Status : [Member] | Replies : 2
I tried to use that technique of sessions, im passing it from login page and using it on another page, now i recieve this error "Object reference not set to an instance of an object."

here im passing it
Session["UserName"] = Login1.UserName;

then accessing on different page like this
username = Session["UserName"].ToString();

Please help me on how can i access it.




Responses

Posted by: Mouli on: 9/23/2009 [Member] Starter

Up
0
Down
Login1.UserName is Null. Thats why you are getting that error. Check what value you are getting in the Login1.UserName property. Can you tell me how exactly you retrieve the credentials from the login page in this page?

Mongz, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 9/23/2009 [Member] Bronze

Up
0
Down
You can get this error in two situations.
1___ If the Login1.UserName = Null
2___ Session["UserName"] = Null

Please review your code. Please you Convert.ToString(...) instead of .ToString()

Mongz, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response