We are developing a ASP.NET web application in which we need to access a shared drive and search for a directory, if it is present or not. But while accessing using the PATH the application is showing error. For that case we thought to use Impersonation technique. We added the Identity tag in the Web.config file with the username and password but it's showing below error: Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not create Windows user token from the credentials specified in the config file. Error from the operating system 'The user name or password is incorrect.
So we tried to add the Impersonation logic in a separate class in code and use the instance while trying to access the shared folder using the given path, but still it's showing error.
we have used the code for impersonation class from the below link: https://daoudisamir.com/impersonate-users-in-c/
in the above code inside the ImpersonateValidUser() the if condition for LogonUser() method is getting false hence it's corresponding else part is getting executed and throwing error.
It will be great if anyone can help us with this.