asp.net web api - Impersonation attribute for uploading a file in network- wep api -
we have apiimpersonate
attribute impersonate shared network uploading files. in several of our projects working fine; , in project it's doing impersonation , see isauthenticated
in debug mode windowsidentity
true
.
the problem when use directory.createdirectory()
directly in api controller there no issue, but when call asset service in file create directory gives me error "server can not perform request".
here code in question:
public static windowsimpersonationcontext impersonate(string domain, string username, string password) { var token = intptr.zero; var tokenduplicate = intptr.zero; const int logon32logoninteractive = 2; const int logon32logonnewcredentials = 9; const int logon32providerdefault = 0; if (reverttoself()) { if (logonuser(username, domain, password, logon32logonnewcredentials, logon32providerdefault, ref token) != 0) { if (duplicatetoken(token, 2, ref tokenduplicate) != 0) { var tempwindowsidentity = new windowsidentity(tokenduplicate); var impersonationcontext = tempwindowsidentity.impersonate(); if (impersonationcontext != null) { closehandle(token); closehandle(tokenduplicate); return impersonationcontext; } } } else { var ret = marshal.getlastwin32error(); console.writeline(ret.tostring(cultureinfo.invariantculture), "error"); } } if (token != intptr.zero) { closehandle(token); } if (tokenduplicate != intptr.zero) { closehandle(tokenduplicate); } return null; }
Comments
Post a Comment