从数据库下载exe文件 [英] Downloading exe files from database

查看:47
本文介绍了从数据库下载exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些exe文件已上传到我的数据库中,因为我不希望这些文件可以公开访问.我尝试使用链接按钮和通用处理程序使用以下代码来提供文件:

I have some exe files that I've uploaded into my database as I don't want them to be publicly accessible. I tried using a link button and a generic handler to serve the file using the following code:

Context.Response.Clear()
Context.Response.ContentType = "application/exe"
Context.Response.AppendHeader("Content-Disposition", "filename=program.exe")
Context.Response.BinaryWrite(binaryfile)

问题:Google Chrome浏览器不将下载内容与其他任何exe文件一样对待,而是在下载后报告"program.exe不常用下载且可能很危险".带有放弃"按钮,并且保留"选项隐藏在上下文菜单下.

The problem: Google Chrome does not treat the download as any other exe, instead after downloading it reports "program.exe is not commonly downloaded and could be dangerous." with a "discard" button and the option to "keep" the download is hidden under a context menu.

还有其他/更好的方法来服务数据库中存储的exe文件吗?

Is there any other/better way to serve exe files stored in the database?

推荐答案

我很少在野外看到 application/exe .对可执行文件使用 application/octet-stream 更为常见.

I don't often see application/exe in the wild. It's more common to use application/octet-stream for executable files.

如果您使用的是.NET,那么我暂时假设您使用的是IIS.(如果不是这种情况,请纠正我.)如果是,请此(旧的,但仍然有用)的MIME类型和文件扩展名列表可能会有所帮助.

If you're using .NET, then I'm going to assume for a moment that you're using IIS. (Correct me if this is not the case.) If so, then this (old, but still useful) list of MIME types and file extensions may be helpful.

自然地,您将无法从任何实际意义上摆脱服务器端的任何浏览器端限制.您可以修改发送给客户端的标头,但最终由客户端决定如何处理响应.

Naturally, you won't be able to get around any browser-side restrictions from the server side in any real sense. You can modify the headers you send to the client, but in the end it's up to the client what to do with the response.

这篇关于从数据库下载exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆