Tuesday, February 23, 2010

X++ Code to restrict user login multiple times in ax2009

Copy Paste the Following Code in startupPost method of info class in AOT

void startupPost()
{
// To restrict user login form second login
xSession session;
SysClientSessions SysClientSessions;
UserId currentUserId;
int counter;

;

currentUserId = curUserId();

if(currentUserId!="Admin")// Allow Admin User to login multiple time
{
while select SysClientSessions
where SysClientSessions.userId == currentUserId &&
SysClientSessions.Status == 1 // 1 : Login 0 : Logout
{
session = new xSession(SysClientSessions.SessionId, true);
if (session && session.userId())
{
counter++;
}
}

if(counter>=2)
{
Box::stop("Already Logged-in : The same user id can't log in twice.");
infolog.shutDown(true);
}
}
}


Please take backup of your application before copying code

5 comments:

Unknown said...

Thank you very much! this is what I was looking for months ago! You made my day!

Anonymous said...

Thank you.

Anonymous said...

Thank you.

TodayBreakingNews said...

if we cannot change the class code, is there any other user level customization to stop multiple sessions of AX

Deepankar Sahdev said...

@Arif You need have code customisation access there is no user level setups available for such