I've been trying to implement the impersonation on my c# application to save files on NAS drive, but even though my credentials are valid. I keep getting an error as The username or password is incorrect. it worked a couple of times and then it kept failing. this happened when I deployed it on IIS.
if (RevertToSelf())
{
if (LogonUser(AppConstants.NASAccessUserName, AppConstants.NASServerDomain,
AppConstants.NASAccessPassword, LogonType.Interactive,
LogonProvider.Default, out _token))
{
if (DuplicateToken(_token, SecurityImpersonationLevel.Impersonation, out _tokenDuplicate))
{
var tempWindowsIdentity = new WindowsIdentity(_tokenDuplicate);
_impersonationContext = tempWindowsIdentity.Impersonate();
return true;
}
throw new Win32Exception(Marshal.GetLastWin32Error());
}
throw new Win32Exception(Marshal.GetLastWin32Error());
}
throw new Win32Exception(Marshal.GetLastWin32Error());
I've tried using LOGON32_LOGON_NEW_CREDENTIALS as the logon Type too along with LOGON32_PROVIDER_WINNT50, but no luck. what am I missing here? is there any configuration on the NAS server? or anything else to add to this?