public static void LogError(ErrorCode pCode, string pStackTrace = null, string pErrorMessage = null) { ErrorLogTableAdapter logAdapter = new ErrorLogTableAdapter(); bool addedRow = false; if (HttpContext.Current.User.Identity.IsAuthenticated) { SysUserTableAdapter adapter = new SysUserTableAdapter(); ONyRDataSet.SysUserDataTable table = adapter.GetDataByUserName(HttpContext.Current.User.Identity.Name); if (table.Count > 0) { logAdapter.ErrorLog(table[0].ID, (int)pCode, pStackTrace, pErrorMessage); addedRow = true; } adapter.Dispose(); table.Dispose(); } if (!addedRow) { logAdapter.ErrorLog(null, (int)pCode, pStackTrace, pErrorMessage); } logAdapter.Dispose(); }
public static void CreationCookie(object sender, System.Web.ApplicationServices.CreatingCookieEventArgs e) { ONyRDataSet.SysUserDataTable users; ONyRDataSet.SysSessionDataTable sessions; ONyRDataSet.SysSessionRow session; SysUserTableAdapter userAdapter = new SysUserTableAdapter(); users = userAdapter.GetDataByUserName(e.UserName); if (users.Count == 0) { throw new ONyRException(ErrorCode.InvalidCredentialsError); } ONyRDataSet.SysUserRow user = users[0]; SysSessionTableAdapter sessionAdapter = new SysSessionTableAdapter(); sessions = sessionAdapter.GetDataByUserID(user.ID); foreach (ONyRDataSet.SysSessionRow row in sessions) { sessionAdapter.Delete1(row.ID); } sessionAdapter.CreateSession(user.ID); sessions = sessionAdapter.GetDataByUserID(user.ID); session = sessions[0]; sessionAdapter.Dispose(); userAdapter.UpdateLoginDate(user.ID); userAdapter.Dispose(); HttpContext.Current.Response.Cookies.Add(new HttpCookie("UserId", user.ID.ToString())); HttpContext.Current.Response.Cookies.Add(new HttpCookie("SessionId", session.ID.ToString())); }