0

我想从我的 Web 应用程序向域内的服务器写入文件,但是托管我的 Web 应用程序的服务器不在该域中。我正在尝试使用模拟,但它给出了这个错误:登录失败:未知用户名或密码错误。

以下是我的模拟代码:

 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_PROVIDER_DEFAULT 和 LOGON32_PROVIDER_WINNT50

但不幸的是,这些设置也没有运气。谁能帮我确定这是来自域外的模仿。

4

0 回答 0