点击链接不在浏览器打开而是弹出下载对话框

怎样点击直接下载
直接让客户端浏览器下载已知类型的文件
实现点击链接直接下载文件
点击后直接下载而不是将其打开
写下载链接的时候,对于txt,doc,xls等文本类型的文件,点击链接时怎样才能直接下载,而不打开呢
如何左键点击连接连接直接下载.txt文件

网上搜到提供的方法都是用fso stream读取文件,然后通过修改http headers的办法,比较麻烦,而且效率很低。

IIS里边有一项Custom HTTP Headers 的选项,可以直接在里边修改 Content-dispositionattachment即可。



Microsoft provides a way to override this "stream now" behavior at the server side using a custom HTTP Header in IIS. To add the custom header, launch Internet Information Services Manager and expand your Web sites to reveal the folder where multimedia content is stored. Right-click this folder and choose Properties. Click the HTTP Headers tab, followed by the Add button.

For the Custom header name type: Content-disposition
For the Custom header value type: attachment

Click OK, click Apply, click OK.

Visit one of the Web pages linking to your content download and test the links. You should be presented with the Save As dialog.

There is a catch to this solution. By setting the Content-disposition for the entire folder, your server will pop the Save As dialog box for any file called by a Web browser, including Web pages. There are two ways to solve this problem: only store media files in the folder where you modify the Content-disposition or set the attribute on-the-fly using code.

原文来自:http://www.jakeludington.com/windows_media_server_admin/20041209_using_custom_http_headers_to_prompt_for_video_file_downloads.html

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值