Login users at the same time problemes in signalr -


im working on social network asp.net , signalr . have simple login page, if finds user in database creates application variable , redirect user profile page , in page invoke connect method declared in hub class , method takes userid in session , give frind list of user . works great when 2 or many users loged in @ different time. thing is, when 2 or several users logged in @ same time , connect method declared in hub takes last user id stored in application variable , give friend list of last user id , send user connected .

i can't find correct approach.

thanks in advance help.

loggin page code :

    protected void btn_login_click(object sender, eventargs e)             {                 tbl_user user = new tbl_user();                 user = fonctioncommun.login(txt_username.text , txt_password.text);                 if (user != null)                 {                     application["userid"] = user.userid.tostring();                         response.redirect("profile.aspx");                 }                 else {                     label1.visible = true;                 }          } 

my connect method code :

public void connect() {             userid = guid.parse(httpcontext.current.application["userid"].tostring());   string output = "";   if (listonlineuser.count(x => x.userid == userid) == 0)  {  listonlineuser.add(new onlineusers { userid = userid, connetionid = guid.parse(context.connectionid) });                 objchat.setonline(userid);                      listfriends = objchat.getfriendloginstatus(userid);             }             foreach (tbl_user item in listfriends)             {                 if (item.status == "1")                 {                     onlineusers onlinefriend = listonlineuser.firstordefault(x => x.userid == guid.parse(item.userid.tostring()));                     if (onlinefriend != null)                     {                         using (fiesta_advisorentities bd = new fiesta_advisorentities())                         {                             tbl_user obj_user = bd.tbl_user.where(o => o.userid == userid).firstordefault();                             if (obj_user.profileimage != null)                             {                                 string ext = bd.assets.where(o => o.url == obj_user.profileimage).select(o => o.mimetype).firstordefault();                                 userdetaille res = new userdetaille() { userid = guid.parse(obj_user.userid.tostring()), username = obj_user.username, profileimage = obj_user.profileimage.tostring(), ext = ext };                                  output = jsonconvert.serializeobject(res);                             }                             else {                                  userdetaille res = new userdetaille() { userid = guid.parse(obj_user.userid.tostring()), username = obj_user.username, profileimage = "111", ext = "png" };                                  output = jsonconvert.serializeobject(res); }                              clients.client(onlinefriend.connetionid.tostring()).onnewuserconnect(output);                         }                     }                 }             }             clients.caller.showfriends(listfriends);         } 

try session variable instead of application variable. application variable shared through out application working. whenever new user override. if use session variable never override other user


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -