C# 来自域外的模拟
我想从我的web应用程序向域内的服务器写入文件,但我的web应用程序所在的服务器不在该域内。我试图使用模拟,但它给出了以下错误:登录失败:未知用户名或错误密码 下面是我要模拟的代码:C# 来自域外的模拟,c#,impersonation,C#,Impersonation,我想从我的web应用程序向域内的服务器写入文件,但我的web应用程序所在的服务器不在该域内。我试图使用模拟,但它给出了以下错误:登录失败:未知用户名或错误密码 下面是我要模拟的代码: private bool impersonateValidUser(String userName, String domain, String password) { WindowsIdentity tempWindowsIdentity; IntPtr token =
private bool impersonateValidUser(String userName, String domain, String password)
{
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
if (RevertToSelf())
{
if (LogonUser(userName, domain, password, LOGON_TYPE_NEW_CREDENTIALS, LOGON32_PROVIDER_WINNT50, ref token) != 0)
{
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
if (impersonationContext != null)
{
CloseHandle(token);
CloseHandle(tokenDuplicate);
return true;
}
}
}
}
if (token != IntPtr.Zero)
CloseHandle(token);
if (tokenDuplicate != IntPtr.Zero)
CloseHandle(tokenDuplicate);
return false;
}
我已尝试使用LOGON32\u提供程序\u默认值和LOGON32\u提供程序\u WINNT50
但不幸的是,这些设置也没有带来好运。有人能帮我确定这是域外的模拟吗 您需要在服务器之间设置NTLM或Kerberos,以便有一定程度的信任来进行模拟。如果您只是尝试将文件写入某个位置,则可以将该位置设置为文件共享,并授予您尝试从中写入的域帐户权限。请尝试使用