C# 将 UNC 路径与凭据一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10214596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 12:55:13  来源:igfitidea点击:

Using UNC path with credentials

c#.netwindows.net-4.0

提问by avmauricio

I'm working on an app that uses an UNC path to access remote files in the same LAN. The problem is that when access is attempted it throws an exception related to Windows credentials.

我正在开发一个应用程序,该应用程序使用 UNC 路径访问同一 LAN 中的远程文件。问题在于,当尝试访问时,它会引发与 Windows 凭据相关的异常。

Is there a way to add credentials to my UNC path?

有没有办法将凭据添加到我的 UNC 路径?

Thank you

谢谢

回答by Fer

It might be useful for you to use the NetUseAdd function from the windows api http://msdn.microsoft.com/en-us/library/windows/desktop/aa370645(v=vs.85).aspx. It allows you to access a directory through its UNC path.

使用 windows api http://msdn.microsoft.com/en-us/library/windows/desktop/aa370645(v=vs.85).aspx 中的 NetUseAdd 函数可能对您有用。它允许您通过其 UNC 路径访问目录。

回答by Derek Risling

Looks like Win32 APIs are the most common way to handle this. Check out this SO post Accessing a Shared File (UNC) From a Remote, Non-Trusted Domain With Credentials

看起来 Win32 API 是处理此问题的最常用方法。查看此 SO 帖子 从具有凭据的远程非受信任域访问共享文件 (UNC)