我坚持这个问题.
我有UNC分享,我知道帐户详细信息,有成功,但它无法访问我的本地系统.我可以通过以下方式访问远程UNC:
var token = default(IntPtr);
var context = default(WindowsImpersonationContext);
LogonUser(_config.Username, _config.Domain, _config.Password, 2, 0, out token);
context = WindowsIdentity.Impersonate(token);
//TODO :: System.IO operations
File.Copy("remote-unc-path","local-path",true); // Exception : Access is denied.
context.Undo();
CloseHandle(token);
Run Code Online (Sandbox Code Playgroud)
但是,我无法在模拟期间访问我的本地系统,因为帐户无法访问它.
在这种情况下如何复制文件?我是否需要使用像缓冲区这样的东西来打开/关闭模拟?
我对 ConfigurationProperty 的 DefaultValue 有一个小问题。
这是我的 XML 配置的一部分:
<Storage id="storageId">
<Type>UNC</Type>
</Storage>
Run Code Online (Sandbox Code Playgroud)
为了处理此配置,我创建了“StorageElement:ConfigurationElement”:
public class StorageElement : ConfigurationElement
{
private static readonly ConfigurationPropertyCollection PropertyCollection = new ConfigurationPropertyCollection();
internal const string IdPropertyName = "id";
internal const string TypePropertyName = "Type";
public StorageElement()
{
PropertyCollection.Add(
new ConfigurationProperty(
IdPropertyName,
typeof(string),
"",
ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey
));
PropertyCollection.Add(
new ConfigurationProperty(
TypePropertyName,
typeof(ConfigurationTextElement<string>),
null,
ConfigurationPropertyOptions.IsRequired));
}
public string Id
{
get
{
return base[IdPropertyName] as string;
}
}
public string Type
{
get
{
return (base[TypePropertyName] …Run Code Online (Sandbox Code Playgroud)