我有一個在Windows域中的服務器上自動生成的文件,稱爲「prod」,我需要讓VB.NET將該文件傳輸到另一個文件服務器在另一個Windows域中,例如「QA」,其中QA和Prod完全具有不同的憑證,並且每次打開目標文件夾時都必須驗證該憑證。使用VB.NET跨域文件複製
因此,我想常規filecopy方法將無法正常工作,有沒有另一種方法可以實現這一目標?
非常感謝!
我有一個在Windows域中的服務器上自動生成的文件,稱爲「prod」,我需要讓VB.NET將該文件傳輸到另一個文件服務器在另一個Windows域中,例如「QA」,其中QA和Prod完全具有不同的憑證,並且每次打開目標文件夾時都必須驗證該憑證。使用VB.NET跨域文件複製
因此,我想常規filecopy方法將無法正常工作,有沒有另一種方法可以實現這一目標?
非常感謝!
如何像這樣
<DllImport("advapi32.dll")> _
Public Shared Function LogonUser(lpszUsername As String, lpszDomain As String, lpszPassword As String, dwLogonType As Integer, dwLogonProvider As Integer, phToken As IntPtr) As Boolean
End Function
<DllImport("kernel32.dll")> _
Public Shared Function CloseHandle(hObject As IntPtr) As Boolean
End Function
Public Shared Function OpenFileWithAccount(filename As String, username As String, domain As String, password As String) As Stream
Dim token As IntPtr
If Not LogonUser(username, domain, password, 2, 0, token) Then
Throw New Win32Exception()
End If
Try
Using WindowsIdentity.Impersonate(token)
Return File.OpenRead(filename)
End Using
Finally
CloseHandle(token)
End Try
End Function
,並呼籲
Dim stream as Stream
stream = OpenFileWithAccount("filePath","userName","prod","password")
令牌= Marshal.AllocHGlobal(8)
不要在你的代碼解決這個問題,存儲的用戶名/密碼的你的代碼或配置數據是根本上有缺陷的。讓局域網管理員用外部信任對此進行分類,他可以在serverfault.com上詢問它。 http://technet.microsoft.com/en-us/library/cc787646%28WS.10%29.aspx – 2011-03-12 17:56:45