How to maintain Session in a facebook c# application

Feb 22, 2008 at 7:38 PM

I am getting object reference error, when i am using Session object
my code like.
Customer_id = new SocTel().login(txtFname.Text, txtLname.Text, txtPassword.Text);
if (Customer_id != 0)
Session"Customer_id" = Customer_id;

accessing second page like :

protected int Customer_id = 0;
protected void Page_Load(object sender, EventArgs e)
Customer_id = Convert.ToInt32(Session"Customer_id".ToString());

please help to me here how to maintain session for facebook

Feb 25, 2008 at 8:49 PM
Can you be a little more specific? When you say "session for facebook", what do you mean? If you use the CanvasBasePages then those maintain your facebook session and handle login / Authentication. Your facebook session being the seesion id from facebook after a user logs in and you making calls based on that session. In your code it seems like you are just using regular ASP.NET session to store a customer id. Are you just have problems stroring / retreiving your customer id out of session? If your question in general refers to Session state, then reading this might help :

From looking at you code, a few things Session"customerId" doesn't need the to string since you can just convert the object to an int. Not sure what this is returning, Customer_id = new SocTel().login(txtFname.Text, txtLname.Text, txtPassword.Text); but did you debug? Is that actually retruning a value? If it returns 0 then you are never setting anyhing in session on the first page. So on the second page you'll get an exception when you try to tostring/convert on a null. On the second page you can do something like int.TryParse insetead of casting so that if the customer id is not in session it won't throw an exception.

This doesn't seem like a Facebook toolkit issues though. If it's not specific to this project, you'd probably get a faster response on the ASP.NET forums.

Feb 25, 2008 at 11:21 PM
Hi kmarshal,

Thanks for your worthful response.

I solved that problem, i was using fbml, now i changed to iframe...
it was working fine to me