locked
A specified logon session does not exist. It may already have been terminated. RRS feed

  • Question

  • User430178104 posted

    Hi,
    I am using below code to reset windows password. but it is throwing below error.

    A specified logon session does not exist. It may already have been terminated.

    using (var context = new PrincipalContext(ContextType.Machine, domain, null, ContextOptions.Negotiate, "XXXXX", "YYYYY"))
                    using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, userName))
                    {
                        user.SetPassword(newPassword);
                    }

    Thursday, January 24, 2019 6:41 AM

All replies

  • User1724605321 posted

    Hi pathipati ,

    Could you please explain more about your requirement  ? Do you want to change membership/identity user's password or you want to change windows account user's password ?

    Best Regards,

    Nan Yu

    Friday, January 25, 2019 3:41 AM
  • User430178104 posted

    Hi, Nan Yu,

    Thanks for your response.

    I am looking to Reset Users Windows Password from Administration Level.

    Friday, January 25, 2019 3:57 AM
  • User1724605321 posted

    Hi pathipati ,

    I haven't met the issue  . Where do you put the codes , in global.ascx  ? You can also refer to below links for code sample :

    https://stackoverflow.com/a/53842740/5751404

    https://stackoverflow.com/questions/38997727/changing-active-directory-user-passwords-in-c-asp-net-after-ms-patch-kb3167679 

    Best Regards,

    Nan Yu

    Friday, January 25, 2019 8:54 AM
  • User430178104 posted

    My above code is working when the AppPool is set to 'LocalSystem' and not 'ApplicationPoolIdentity'. is it harm to set AppPool to LocalSystem

    Friday, January 25, 2019 9:55 AM
  • User1724605321 posted

    Hi pathipati,

    Local system has the highest privilege and should avoid , so the problem is the service account was not given the permissions to change/reset passwords if you are using service account with appropriate AD permissions.

    Best Regards,

    Nan Yu

    Tuesday, January 29, 2019 7:17 AM