如何通过 IIS 和 ASP 从 UNC 映射共享下载文件
我正在编写一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 ASP 人员,所以我的这些答案可能完全错误。
关于路径,我认为你不应该使用MapPath,因为这是为了获取相对路径,并且你已经知道物理路径,所以你不能将其更改为:
关于帐户,我认为你需要使用模拟,此链接似乎只是讨论这个:
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:
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