I'm so confused here. Ok, so I'm trying to create a session object that we can use to store some info.
My plan is to create a new FacebookSession object whenever a user logs into Facebook (after they are redirect back to our site). I can set state for this by using the auto generated cookie that the facebook SDK creates after they've logged into facebook. So I can hopefully grab that cookie when they get back server-side and create my FacebookSession object and set state off the cookie info (userID, token, etc.) that contains info I need for that user's facebook account.
I don't understand session state very well and also threads as it relates to a page. So, can't I check for the existing session object on every page or is it lost when you go from page to page? Lets say I create this initial FacebookSession object when the user gets back and then redirect them immediately thereafter to another page Response.Redirect. Do I lose that object? I think so right? because a new page request spawns a new thread in IIS for that user right? And then you start off with a clean slate in terms of any objects you created in memory have been wiped.
So then I need to persist it in the DB and then with a method such as GetCurrentSession, somehow look up that current user and try to grab current session information in a table lets say called FacebookSession where I could store their facebookUserID, token, etc.
right?
Finally, at any time, how would I know how to check for that user in the DB? I need some sort of unique ID? So what I did was to add a Pk column that actually will utilize an existing sessionID every user on our site has..which is the overall global vistiting session that they get when they visit our site.
So using that I can uniquely identify their facebook Session if it exists by looking it up in my开发者_StackOverflow table via their "global session ID". But the problem ultimately that I run into is now in order to call GetCurrentSession() from my FacebookSession.cs object, I need to somehow pass it that global ID. I can do this through the constructor (I'm not making this a singleton). But then now that object and several other objects are dependent on this global ID needed to look up a user's Facebook session. Well what if we want to reuse this library/wrapper I've created in some other project that doesn't want to use the global session as the PK, then I'm kinda screwed.
So this is the headache I have right now. Pretty much I just want some opinions and verification if I'm going down the right path here and if I'm right about memory, IIS, threads, and session state in terms of a way to attack this one.
I guess you should check this description from MSDN.
精彩评论