当多人尝试保存事务时,用户 ID 将变为空数据库
When multiple people try to save a transaction the user id is going null to the database
当多人尝试保存交易时,用户 ID 将变为空数据库。我每次都根据数据库中的会话 ID 获取用户信息。
我也尝试过查询字符串和会话。
下面提到的是从数据库中检索会话 ID 和系统名称的记录用户信息的代码。
我以前调用这些构造函数是web方法
public clsLoggedUser()
{
try
{
string strUserId = "";
if (HttpContext.Current.Request.QueryString["x"] == null)
{
string strSessionID = HttpContext.Current.Session.SessionID;
string strUrl = HttpContext.Current.Request.UrlReferrer.Authority;
string strSystemName = Convert.ToString(System.Net.Dns.Resolve(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName);
OracleParameter[] objParam = new OracleParameter[3];
objParam[0] = new OracleParameter("SESSIONID", OracleType.VarChar);
objParam[1] = new OracleParameter("SYSNAME", OracleType.VarChar);
objParam[2] = new OracleParameter("URL", OracleType.VarChar);
objParam[0].Value = strSessionID.Trim();
objParam[1].Value = strSystemName.Trim();
objParam[2].Value = strUrl.Trim();
DataTable dtUserDetails = clsOracleAccess.StaticExecuteDataset(CommandType.StoredProcedure, "PACKCOMMON.GETLOGGEDUSERID", objParam, true).Tables[0];
if (dtUserDetails.Rows.Count > 0)
{
strUserId = dtUserDetails.Rows[0]["APPLOCKID_NR"].ToString();
}
else
{
Exception ex = new NullReferenceException();
clsErrorLogEntity.fn_AddNewErrorLog(DateTime.Now, "clsLoggedUser.cs (clsLoggedUser(-1)) [" + ex.Source + "]:" + ((String[])ex.StackTrace.Split(':'))[((String[])ex.StackTrace.Split(':')).Length - 1] + "", ex.Message, ex);
}
}
else
{
strUserId = HttpContext.Current.Request.QueryString["x"].ToString().Trim();
}
if (!String.IsNullOrEmpty(strUserId))
{
OracleParameter[] objParam = new OracleParameter[1];
objParam[0] = new OracleParameter("USERID", OracleType.Number);
objParam[0].Value = Int32.Parse(strUserId);
DataTable dtUserDetails = clsOracleAccess.StaticExecuteDataset(CommandType.StoredProcedure, "HMPACK.GETUSERINFOBYID", objParam, true).Tables[0];
if (dtUserDetails.Rows.Count > 0)
{
UserID = Convert.ToInt32(dtUserDetails.Rows[0]["APPID_NR"].ToString());
UserName = dtUserDetails.Rows[0]["APPUNAME_CD"].ToString();
Password = dtUserDetails.Rows[0]["APPUACCESS_CD"].ToString();
UserCode = dtUserDetails.Rows[0]["APPCODE_CD"].ToString();
IsAdmin = Convert.ToChar(dtUserDetails.Rows[0]["ADMINUSER_YN"].ToString());
UserConID = Convert.ToInt32(dtUserDetails.Rows[0]["CONID_NR"].ToString());
IsLoggedIn = true;
blIsAdmin = IsAdmin == 'Y' ? true : false;
}
}
}
catch (Exception ex)
{
}
}
}
clsLoggedUser objclsLoggedUser = new clsLoggedUser();
objclsLoggedUser.UserName;
objclsLoggedUser.UserID;
(抱歉还不能发表评论)
我注意到 运行 通过该代码并以“objclsLoggedUser.UserName == null”结束的可能性有很多。如果发生异常,您可以使用 'clsErrorLogEntity.fn_AddNewErrorLog' 进行记录,但 'if (!String.IsNullOrEmpty(strUserId))' 没有其他错误记录。您的 'catch (Exception ex)' 也没有记录任何内容。
如果您在这些位置设置断点并 运行 代码,您很可能会找到罪魁祸首。或者在 'catch (Exception ex)' 设置后:
catch (Exception ex)
if(UserName == null)
throw new IllegalStateException($"User is NULL, HELP!! Some info: {HttpContext.Current.Session.SessionID}");
在 throw 上设置断点或观察错误以了解问题所在。
当多人尝试保存交易时,用户 ID 将变为空数据库。我每次都根据数据库中的会话 ID 获取用户信息。 我也尝试过查询字符串和会话。
下面提到的是从数据库中检索会话 ID 和系统名称的记录用户信息的代码。
我以前调用这些构造函数是web方法
public clsLoggedUser()
{
try
{
string strUserId = "";
if (HttpContext.Current.Request.QueryString["x"] == null)
{
string strSessionID = HttpContext.Current.Session.SessionID;
string strUrl = HttpContext.Current.Request.UrlReferrer.Authority;
string strSystemName = Convert.ToString(System.Net.Dns.Resolve(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName);
OracleParameter[] objParam = new OracleParameter[3];
objParam[0] = new OracleParameter("SESSIONID", OracleType.VarChar);
objParam[1] = new OracleParameter("SYSNAME", OracleType.VarChar);
objParam[2] = new OracleParameter("URL", OracleType.VarChar);
objParam[0].Value = strSessionID.Trim();
objParam[1].Value = strSystemName.Trim();
objParam[2].Value = strUrl.Trim();
DataTable dtUserDetails = clsOracleAccess.StaticExecuteDataset(CommandType.StoredProcedure, "PACKCOMMON.GETLOGGEDUSERID", objParam, true).Tables[0];
if (dtUserDetails.Rows.Count > 0)
{
strUserId = dtUserDetails.Rows[0]["APPLOCKID_NR"].ToString();
}
else
{
Exception ex = new NullReferenceException();
clsErrorLogEntity.fn_AddNewErrorLog(DateTime.Now, "clsLoggedUser.cs (clsLoggedUser(-1)) [" + ex.Source + "]:" + ((String[])ex.StackTrace.Split(':'))[((String[])ex.StackTrace.Split(':')).Length - 1] + "", ex.Message, ex);
}
}
else
{
strUserId = HttpContext.Current.Request.QueryString["x"].ToString().Trim();
}
if (!String.IsNullOrEmpty(strUserId))
{
OracleParameter[] objParam = new OracleParameter[1];
objParam[0] = new OracleParameter("USERID", OracleType.Number);
objParam[0].Value = Int32.Parse(strUserId);
DataTable dtUserDetails = clsOracleAccess.StaticExecuteDataset(CommandType.StoredProcedure, "HMPACK.GETUSERINFOBYID", objParam, true).Tables[0];
if (dtUserDetails.Rows.Count > 0)
{
UserID = Convert.ToInt32(dtUserDetails.Rows[0]["APPID_NR"].ToString());
UserName = dtUserDetails.Rows[0]["APPUNAME_CD"].ToString();
Password = dtUserDetails.Rows[0]["APPUACCESS_CD"].ToString();
UserCode = dtUserDetails.Rows[0]["APPCODE_CD"].ToString();
IsAdmin = Convert.ToChar(dtUserDetails.Rows[0]["ADMINUSER_YN"].ToString());
UserConID = Convert.ToInt32(dtUserDetails.Rows[0]["CONID_NR"].ToString());
IsLoggedIn = true;
blIsAdmin = IsAdmin == 'Y' ? true : false;
}
}
}
catch (Exception ex)
{
}
}
}
clsLoggedUser objclsLoggedUser = new clsLoggedUser();
objclsLoggedUser.UserName;
objclsLoggedUser.UserID;
(抱歉还不能发表评论) 我注意到 运行 通过该代码并以“objclsLoggedUser.UserName == null”结束的可能性有很多。如果发生异常,您可以使用 'clsErrorLogEntity.fn_AddNewErrorLog' 进行记录,但 'if (!String.IsNullOrEmpty(strUserId))' 没有其他错误记录。您的 'catch (Exception ex)' 也没有记录任何内容。 如果您在这些位置设置断点并 运行 代码,您很可能会找到罪魁祸首。或者在 'catch (Exception ex)' 设置后:
catch (Exception ex)
if(UserName == null)
throw new IllegalStateException($"User is NULL, HELP!! Some info: {HttpContext.Current.Session.SessionID}");
在 throw 上设置断点或观察错误以了解问题所在。