I m really sorry for unclear question title but I am a bit confused about it myself.
I m running my website on IIS and on the top its displaying the username of the user who is currently logged in. my website is hosted on a local server and various users are accessing it simultaneously.
PROBLEM
Each time a user opens the site it displays the username of the previous user who just recently visited the site.
CODE
This is the code I am using on my global.asax file.
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
// code to get the current user name when running from IIS
System.Security.Principal.IPrincipal _User;
_User = System.Web.HttpContext.Current.User;
System.Security.Principal.IIdentity _Identity;
_Identity = _User.Identity;
string _Value;
_Value = _Identity.Name.Substring(_Identity.Name.IndexOf(@"\") + 1);
DataTable dtId = CetDatabase.GetEmployeDetails(_Value);
if (dtId.Rows.Count > 0)
{
Session["teamid"] = dtId.Rows[0]["TEAMID"].ToString();
Session["projectid"] = dtId.Rows[0]["PROJECTID"].ToString();
Session["memberid"] = dtId.Rows[0]["MEMBERID"].ToString();
CeteraQMS.Main_Master.projectname = dtId.Rows[0]["PROJECTNAME"].ToString();
CeteraQMS.Main_Master.username = _Value;
CeteraQMS.Main_Master.teamname = dtId.Rows[0]["TEAMNAME"].ToString();
Session["role"] = dtId.Rows[0]["MEMBERROLE"].ToString();
}
else
{
Response.Redirect("AccessDenied.aspx");
}
}
I am not sure where I m going wrong.
Thanks in advance
Akhil
This here:
looks like setting a property on a static object. The
Main_Masterproperty looks like a static property on theCeteraQMSclass (whatever those are). And as you know static objects are shared among all users in the application. So don’t use any static objects to store state that is specific to the current user only. If you want to store the username and other user specific properties, it’s better to store them into the Session, the same way you did with theteamid,projectid,memberidandrolevalues.