Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i faced Session Conflicts with different logins using asp.net

When two users access the same page, during post back user1 gets user2 page.

Login Button Code


C#
protected void btn_log_loginin_Click(object sender, EventArgs e)
   {
       try
       {
           _objMasters = new TRANSACTIONBAL();
           _objMasters.ScreenInd = TRANSACTION.userlogin;
           _objMasters.loginname = txt_log_username.Text;
           _objMasters.password = txt_log_password.Text;
           _objDataSet = (DataSet)_objMasters.fnGetData();
           if (_objDataSet != null)
           {
               roleid = Convert.ToInt32(_objDataSet.Tables[0].Rows[0][1]);
           }
           if (roleid == 0)
           {
               loginmsgdsply.Text = "Invalid Login/Inactive Member";
           }
           else if (roleid == 1)
           {
               Session["username"] = txt_log_username.Text;
               Session["Empid"] = _objDataSet.Tables[0].Rows[0][0];
               Session["roleid"] = _objDataSet.Tables[0].Rows[0][1];
               Session["Jobid"] = _objDataSet.Tables[0].Rows[0][2];
               Session["JoinDate"] = _objDataSet.Tables[0].Rows[0][3];

               Response.Redirect("~/Employeedirectory.aspx");
           }
           else if (roleid != 0 && roleid != 1)
           {
               if (_objDataSet.Tables[0].Rows.Count > 0)
               {
                   Session["username"] = txt_log_username.Text;
                   Session["Empid"] = _objDataSet.Tables[0].Rows[0][0];
                   Session["roleid"] = _objDataSet.Tables[0].Rows[0][1];
                   Session["Jobid"] = _objDataSet.Tables[0].Rows[0][2];
                   Session["JoinDate"] = _objDataSet.Tables[0].Rows[0][3];

                  Response.Redirect("~/Default.aspx");
               }
               else
               {
                   loginmsgdsply.ForeColor = Color.Red;
                   loginmsgdsply.Text = "Invalid Login";
               }
           }
       }
       catch (Exception ex)
       {
           //LogError("QuestionBank.aspx", "fnLoadPage", DateTime.Now, ex.Message.ToString());
           //Response.Redirect("Error.aspx", false);
       }
   }
Posted

Hey Raghupathirao,

(I would use switch on "roleid")

Anyway, is looks like it might be something with your function:
C#
_objDataSet = (DataSet)_objMasters.fnGetData();


did you make sure that you get the right _objDataSet back on that call?

* btw, I would use "switch-case" on "roleid" there

Cheers,
Edo
 
Share this answer
 
HI,

Use a
C#
finally{ 
   if(_objMasters != null)
   {
     _objMasters = null;
   }
 }
block in your code and dispose your _objMasters object there and assign null to that object.

This may resolve your problem.

Thanks
 
Share this answer
 
Comments
Joezer BH 21-Jan-13 4:02am    
5+
Good idea that can also be the prob
[no name] 21-Jan-13 5:30am    
Thanks...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900