[英]Get current logged in member user id
我有一个asp.net Web应用程序,当同一网络上的两个或多个用户登录时,我遇到了问题。 我使用查询来检索帐户详细信息,有时会检索在同一网络上登录的其他人的详细信息。
例
John are Lisa在同一WiFi上使用不同的设备和不同的帐户登录。
有时Lisa的帐户详细信息会显示为John在他的帐户中的详细信息,而lisa也是如此。
这是查询的一个例子
// Determine the currently logged on user's UserId value
MembershipUser currentUser = Membership.GetUser();
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
// Retrieve profile Name
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string selectSql = "SELECT (FirstName + ' ' + LastName) FROM User_Profile WHERE UserId = (@UserId)";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand(selectSql, myConnection);
myCommand.Parameters.AddWithValue("@UserId", currentUserId);
Label1.Text = myCommand.ExecuteScalar().ToString();
myConnection.Close();
}
我不确定这个问题是否来自
MembershipUser currentUser = Membership.GetUser();
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
,查询还是我做的不好。
谢谢。
对象currentUser包含属性UserName。 尝试显示该内容以确定您拥有合适的用户是第一位。
检查IIS上的工作线程,它们可能会交叉,并将所有会话设置为同一线程。 通常,如果发生这种情况,他们将切换到最后一个登录的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.