【问题标题】:How to download a file from a UNC mapped share via IIS and ASP如何通过 IIS 和 ASP 从 UNC 映射共享下载文件
【发布时间】:2010-04-24 17:15:59
【问题描述】:

我正在编写一个 ASP 应用程序,它将通过浏览器向客户端提供文件。这些文件位于通过 UNC 路径 (\server\some\path) 运行 IIS 的计算机上可用的文件服务器上。

我想使用类似下面的代码来提供文件。为运行 IIS 的机器提供本地文件可以很好地使用这种方法,我的问题是能够从 UNC 映射共享提供文件:

//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";

//Get the physical path to the file.
string FilePath = MapPath("acrobat.pdf");

//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();

我的问题是如何为文件名指定 UNC 路径。此外,要访问文件共享,我需要使用特定的用户名/密码进行连接。

我会很感激一些关于如何实现这一点的指示(使用上述方法或通过其他方式)。

【问题讨论】:

    标签: asp.net iis unc


    【解决方案1】:

    我不是 ASP 专家,所以我可能对这些答案完全错误。

    关于路径,我认为您不应该使用 MapPath,因为这是为了获得相对路径,而您已经知道物理路径,所以您不能将其更改为:

    string FilePath = @"\\Server\Directory\FileName.txt";
    

    关于帐号,我认为你需要使用模拟,这个链接似乎只是讨论这个:

    http://aspalliance.com/336_Upload_Files_Using_ASPNET_Impersonation_and_UNC_Share.all

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-10
    • 1970-01-01
    • 2018-04-03
    • 2021-08-25
    • 2023-03-31
    • 2019-11-03
    • 1970-01-01
    • 2017-11-04
    相关资源
    最近更新 更多