Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 纯.Net中带凭据的网络文件传输_C#_Asp.net_Networking - Fatal编程技术网

C# 纯.Net中带凭据的网络文件传输

C# 纯.Net中带凭据的网络文件传输,c#,asp.net,networking,C#,Asp.net,Networking,最近,我创建了一个通过网络传输带有凭据的文件的方法。为此,我使用WIN-32API登录用户。LogonUser使用advapi32.dll。这限制了我们在部署web应用程序的操作系统中提供并支持此dll [System.Runtime.InteropServices.DllImport("advapi32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] public sta

最近,我创建了一个通过网络传输带有凭据的文件的方法。为此,我使用WIN-32API登录用户。LogonUser使用advapi32.dll。这限制了我们在部署web应用程序的操作系统中提供并支持此dll

[System.Runtime.InteropServices.DllImport("advapi32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);


private static string CopyToNetwork(string _sourceFile, string _targetFile, string _domain, string _userName, string _password)
{
    IntPtr tokenHandle = new IntPtr(0);
    bool returnValue = LogonUser(_userName, _domain, _password, 9, 3, ref tokenHandle);
    if(returnValue)
    {
        using(WindowsIdentity wid = new WindowsIdentity(tokenHandle))
        {
            using(WindowsImpersonationContext impersonatedUser = wid.Impersonate())
            {
                File.Copy(_sourceFile, _targetFile, IS_OVERWRITE);
            }
        }
    }
}

现在,我们不想要这种依赖性。我们可以用纯.Net做同样的事情吗?这意味着不使用任何WIN API。

在Windows advapi32.dll上始终存在,并且无论如何都不应该重新分发。我计划在Linux上托管web应用程序。