ASP.Net HyperLink和直接下载? [英] ASP.Net HyperLink and Download directly?

查看:72
本文介绍了ASP.Net HyperLink和直接下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要在gridView中有一个超链接"按钮,在其中我可以显示用于直接下载文件的链接.

want to have a Hyperlink-Button in a gridView in which I can display a Link for a direct download of files.

到目前为止,我还可以,但是当我在NavigateURL中链接文件时,没有通过单击获得文件,我必须右键单击->另存为!我不要有帮助吗?

So far I am okay, but when I link the file in the NavigateURL, I don't get the file via click, I must right click -> Save as! That I don't want. Any help?

推荐答案

您可以设置ashx文件处理程序.您的ashx通过查询字符串获取请求,将适当的文件加载到内存中,设置适当的响应头并将文件流式传输到浏览器:

You could set up an ashx file handler. Your ashx takes the request through the querystring, loads the proper file into memory, sets the proper response headers and streams the file to the browser:

FileInfo fileInfo = new FileInfo(PATH-TO-YOUR-FILE);  //You need to specify this
context.Response.ContentType = YOUR-CONTENT-TYPE;  //And this
context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
context.Response.WriteFile(fileInfo.FullName);
context.Response.Flush();
context.ApplicationInstance.CompleteRequest()

如果您对安全性有任何担忧,或者可以跟踪谁下载了什么文件,等等,则可以使您对所传递的内容进行细粒度的控制.

This lets you have some fine-grain control over the content that is being delivered if you have any concerns about security or maybe keeping track of who has downloaded what file, etc.

这篇关于ASP.Net HyperLink和直接下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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