通过 IIS 强制下载网络共享上的文件

发布于 2024-08-06 21:48:32 字数 597 浏览 7 评论 0原文

我正在编写一个快速网页来控制对基于网络的音频文件存储库(讲座录音)的访问。音频文件保存在 SAN 上,并使用 UNC 共享从 Web 服务器进行访问。

我想强制出现“保存”对话框,因为在测试过程中我们发现某些网络浏览器很难保存 mp3 文件。重要的是我们的学生可以保存文件而不是仅仅聆听它。

另一个要求是,只有在学生单击同意尊重文件版权的复选框后,下载链接才可用。

我首先尝试使用网站上经过域用户身份验证的虚拟目录。但是,如果我使用命令按钮打开音频文件的 URL,网络浏览器可能会立即尝试播放它。

相反,我尝试使用 ADODB.stream 并使用stream.LoadFromFile 将文件发送给学生,并使用适当的内容配置来强制下载。由于 LoadFromFile 使用文件路径,因此我无法使用 IIS 虚拟目录,因此必须授予网站对我的网络共享的匿名登录访问权限。我通过使其作为域帐户运行来完成此操作,但这让我有点紧张,因为我认为它不太安全。

即使这样,我仍然无法实现预期的目标,因为stream.LoadFromFile命令似乎拒绝从网络共享读取文件。即使我用来运行该站点的域登录具有对该网络共享的完全访问权限,它也会出现身份验证错误。

对于实现我的目标的替代方法有什么建议吗?

I'm writing a quick web page to control access to a web based repository of audio file (recordings of lectures). The audio files are held on SAN and accessed from the web server using a UNC share.

I want to force a "save" dialog to appear, because during testing we have found that some web browsers make it very difficult to save mp3 files. It is important that our students can save the file as opposed to just listening to it.

The other requirement is that the dowload link should only become available after the student has clicked a checkbox agreeing to respect the copyright on the file.

I first attempted to use a virtual directory on the web site that authenticated as a domain user. However, if I open the URL of audio file with my command button the web browser may immediately try to play it.

Instead of this I have tried to use an ADODB.stream and use the stream.LoadFromFile to send the file to the student with an appropriate content-disposition to force the download. Because LoadFromFile uses a file path I cannot use the IIS virtual directory and so must give the web site's anonymous login access to my network share. I've done this by making it run as a domain account, but this makes me a bit nervous as I believe it to be less secure.

Even then I still cannot achieve the desired goal because the stream.LoadFromFile command appears to refuse to read the file from the network share. It gives an authentication error, even though the domain login I'm using to run the site has full access to that network share.

Any recommendations for alternative means of meeting my goals?

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

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

发布评论

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

评论(3

尤怨 2024-08-13 21:48:32

将文件返回到浏览器时,将 mime-type 设置为“application/x-unknown” - 这将导致浏览器要求您下载,因为它不知道如何处理它。

浏览器有可能会读取文件扩展名并尝试变得聪明,但对此您无能为力。

When returning the file to the browser, set the mime-type to be "application/x-unknown" - this will cause the browser to ask you to download as it won't know how to handle it.

There is the possibility the browser will read the file extension and try and be clever, but there's nothing you can do about this.

不美如何 2024-08-13 21:48:32

您最好的选择是添加以下响应标头。

内容处置:附件; filename=fname.ext

请参阅:http://support.microsoft.com/kb/260519更多信息

Your best bet is add the following your response header.

Content-disposition: attachment; filename=fname.ext

see: http://support.microsoft.com/kb/260519 for more info

橘虞初梦 2024-08-13 21:48:32

我喜欢ck关于更改mime类型的答案(如果我被排名,我会投票)。这将解决不保存的问题。

您可以修改响应标头来更改 mime 类型,而不是使用 ADODB 尝试以下代码。

         Response.Clear()  
         Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)  
         Response.AddHeader("Content-Length", file.Length.ToString())  
         Response.ContentType = "application/octet-stream"  
         Response.WriteFile(file.FullName)  
         Response.End 'if file does not exist  

您还可以尝试使用 ZIP 扩展名压缩音频文件。这将具有相同的效果,并且还减少下载所需的带宽。如果您动态执行此操作,您可能需要考虑缓存压缩文件。

尝试在此处查看完整代码 - http://www.xefteri。 com/articles/show.cfm?id=8

您也可以将版权验证添加到预下载检查中。

I like ck's answer of changing the mime type (i'd Vote it up if i was ranked). This will get arround not saving problem.

You can modify the Response Header's to change the mime type instead of using ADODB Try the following code..

         Response.Clear()  
         Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)  
         Response.AddHeader("Content-Length", file.Length.ToString())  
         Response.ContentType = "application/octet-stream"  
         Response.WriteFile(file.FullName)  
         Response.End 'if file does not exist  

You could also try compressing of the Audio Files with a ZIP extension. This would have the same effect and also lessen the bandwidth required for the download. You may want to consider cacheing your zipped files if you do it dynamically.

Try having a look at the full code here - http://www.xefteri.com/articles/show.cfm?id=8

You could add your Copyright Vertification to the predownload check too.

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