问题描述
我正在尝试将文件从sharepoint复制到unc路径.我正在使用以下代码:
I am trying to copy a file from sharepoint to a unc path. I am using the following code:
var id = new WindowsIdentity("[email protected]");
var p = new WindowsPrincipal(id);
var wic = id.Impersonate();
File.Move(oldName, newName);
wic.Undo();
旧名称为C:\ test.txtnewName是\\ server \ folder \ test.txt
oldname is C:\test.txtnewName is \\server\folder\test.txt
我遇到了错误
A specified logon session does not exist. It may already have been terminated.
如何解决此错误,或者使用共享点将文件从A复制到B(UNC路径).
How do I go about removing this error OR copy a file from A to B(UNC path) using sharepoint.
推荐答案
您实际上并没有获得用于模拟的登录令牌.您需要调用LogonUser API来获取有效的登录令牌,该令牌可用于模拟该用户.
You are not actually getting a logon token to impersonate. You need to call the LogonUser API to get a valid logon token, which you can use to impersonate that user.
请参见此博客条目,例如模拟Windows用户的c#中的代码.您还可以看到此知识库文章,其中也包含c#代码(以及与问题有关的重复令牌调用) .net 1.0)
See this blog entry for example code in c# on impersonating a windows user. You can also see this KB article that also contains c# code (and a duplicatetoken call for issues with .net 1.0)
这篇关于“指定的登录会话不存在.它可能已经被终止.尝试使用WindowsIdentity.Impersonate复制文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!