如何通过 IIS 和 ASP 从 UNC 映射共享下载文件

发布于 2024-08-30 03:23:21 字数 574 浏览 13 评论 0原文

我正在编写一个 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 路径。此外,要访问文件共享,我需要使用特定的用户名/密码进行连接。

我希望得到一些关于如何实现这一目标的指示(使用上述方法或通过其他方式)。

I am writing an ASP application that will serve files to clients through the browser. The files are located on a file server that is available from the machine IIS is running on via a UNC path (\server\some\path).

I want to use something like the code below to serve the file. Serving files that are local to the machine IIS is running on is working well with this method, my trouble is being able to serve files from the UNC mapped share:

//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();

My question is how I can specify a UNC path for the file name. Also, to access the file share I need to connect with a specific username/password.

I would appreciate some pointers on how I can achieve this (either using the approach above or by other means).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少情深 2024-09-06 03:23:21

我不是 ASP 人员,所以我的这些答案可能完全错误。

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

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

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

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

I'm not an ASP guy so I might be completely wrong with these answers.

Regarding the path, I don't think you should be using MapPath, since that's to get a relative path and you already know the physical path so can't you just change that to:

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

Regarding the account, I think you need to use impersonation, this link seems to discuss just this:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文