简体   繁体   English

在两个域之间模拟用户

[英]Impersonate user between two domains

I have a problem with my windows forms application.我的 windows forms 应用程序有问题。 An user is identified in a machine and a domain (main domain), sometimes I need to connect to another domain(secondary domain), then I impersonate the user using logonuser api, then open files, but if I want to copy these files to the main domain the app throws a new exception "The username or password is not correct."在一台机器和一个域(主域)中识别出一个用户,有时我需要连接到另一个域(辅助域),然后我使用logonuser api 模拟用户,然后打开文件,但是如果我想将这些文件复制到应用程序的主域抛出一个新异常“用户名或密码不正确”。

How to copy files between two domains and impersonating user with logonuser without create a memorystream?如何在两个域之间复制文件并使用登录用户模拟用户而不创建内存流?

Sorry for my bad English.对不起,我的英语不好。

It is not possible to impersonate two users (which is essentially what "user in different domains" are) at the same time on the same thread.不可能在同一个线程上同时模拟两个用户(本质上是“不同域中的用户”)。 Either use two different threads impersonated with each variant of the user or constantly switch impersonation depending on which file you are accessing.要么使用两个不同的线程来模拟用户的每个变体,要么根据您正在访问的文件不断地切换模拟。

Note: it may be possible to open each file under corresponding user and then copy may work without switching impersonation - if that works for small sample make sure to read more before relying on it.注意:可以在相应的用户下打开每个文件,然后复制可以在不切换模拟的情况下工作 - 如果这适用于小样本,请确保在依赖它之前阅读更多内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM