gpt4 book ai didi

c# - 如何解决 C# 应用程序中的网络共享连接问题?

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:37 25 4
gpt4 key购买 nike

我可以在资源管理器中看到一个网络共享,但是当我尝试在我的应用程序中访问它时,我得到“找不到网络名称”。

这很奇怪,因为同一台服务器还有我可以访问的其他共享。例如:

string[] example_directories = new string[]{        
Path.Combine(@"\\example01","vaqua"),
Path.Combine(@"\\example01","vaqua-pub"),
Path.Combine(@"\\example01","yesvirginiabeach"),
Path.Combine(@"\\example01","yesvirginiabeach-pub")
};

// output username
Console.WriteLine("User: " + WindowsIdentity.GetCurrent().Name);

// output each response to Directory.Exists
foreach (string directory in example_directories)
try
{
Console.WriteLine(directory + " : " + Directory.GetCreationTime(directory));
}
catch(Exception e)
{
Console.WriteLine(directory + " : " + e.Message.Trim());
}

Console.Read();

输出:

User: domain\myusername\\example01\vaqua : 10/22/2013 7:34:30 AM\\example01\vaqua-pub : 10/22/2013 7:57:42 AM\\example01\yesvirginiabeach : The network name cannot be found.\\example01\yesvirginiabeach-pub : 4/4/2013 10:31:07 AM

我可以在资源管理器中的\example01 上看到所有这四个共享,但是 \example01\yesvirginiabeach 共享在我的应用程序中不存在。

这四个共享都具有相同的权限,我什至打印出我的用户名以确保该应用程序使用我的凭据运行。

我已让我们的管理员重新共享目录并重新申请权限,但无济于事。

解决方案:我的管理员拼错了共享名称:

\\example01\yesvirginiabeach 作为 \\example01\yesvirgniabeach

最佳答案

(在上面的评论中回答并解决了...)

仔细检查名称 "yesvirginiabeach" 是否正确。确保没有什么比看起来像 "i" 但实际上是不同字符的 Unicode 字符更疯狂的了。 (解决方案原来是有人将文件夹名称拼错为 "yesvirgniabeach"。)

对于类似的问题,可以尝试 enumerating the shares看看程序能看到什么。还有 NET USE 命令(打开命令提示符并键入 net use/help;此工具显示当前正在访问的所有共享,并且可以从命令提示符打开新共享,有时会提供有用的状态消息)。

关于c# - 如何解决 C# 应用程序中的网络共享连接问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20691901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com