【问题标题】:Server.MapPath gives error with UNCServer.MapPath 给出 UNC 错误
【发布时间】:2012-12-07 15:31:20
【问题描述】:

这是我的服务器目录(权限很好):

string ServerPath = ("\\\\servername\\Public\\Intranet2007Docs");

我在这里访问它:

DirectoryInfo directory = new DirectoryInfo(Server.MapPath(ServerPath));

这是错误:

任何帮助都会很棒。我不明白为什么它不会映射到 UNC 的路径。

【问题讨论】:

  • @、~、// 和 .都是本地机器上的目录,它们不能访问服务器。

标签: c# unc server.mappath mappath


【解决方案1】:

尽量不要使用server.MapPath:

DirectoryInfo directory = new DirectoryInfo("\\\\servername\\Public\\Intranet2007Docs");

【讨论】:

  • 这是问题所在……它不喜欢地图路径!直接在内部使用 unc 就像一个魅力!谢谢!
【解决方案2】:

您只能在 Web 应用程序内部的路径上使用 MapPath。 Web 应用程序之外的任何路径都没有对应的 URL。

此外,DirectoyInfo 方法对 URL 没有任何用处,因此您根本不应该使用 MapPath

DirectoryInfo directory = new DirectoryInfo(ServerPath);

【讨论】:

    猜你喜欢
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 2010-09-21
    • 2012-07-22
    • 2015-06-13
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    相关资源
    最近更新 更多