asp.net mvc 3 - Manage multiple calls of Membership.GetUser().ProviderUserKey; -


i thinking yesterday how solve issue, because give or check user depended of provideruserkey (id).

so made 1 static function

public static guid getuserid() {     string userid = string.empty;      if(httpcontext.current.session["userid"] != null)     {         userid = httpcontext.current.session["userid"].tostring();     }       if(!string.isnullorempty(userid))     {         return new guid(userid);     }      userid = membership.getuser().provideruserkey.tostring();     httpcontext.current.session["userid"] = userid;     return new guid(userid); } 

main point of class reduce database connections check/get user id.

my problem function not not working, problem if logged user log out , log account?

or better add session value on log in , clear session value on log out?

where can see other problem kind of "get user id"?

if log user out should killing session. when login user have session reinitialized.

note you'll want keep session , forms auth timeouts (assuming using forms auth) in sync each other:

how can handle forms authentication timeout exceptions in asp.net?

this should keep session in line forms auth token. you'll in turn need kill session on logout , intialize upon login.

another alternative implememt own membership provider caches key prevent constant db hits.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -