English 中文(简体)
着手在 as中挽救形象
原标题:Pop up to save image in asp.net

我使用的是p.net 3.5和C#。

I have a image which I want user can download. Like, there would be a download button or link. When user click on this link he will be prompted with a pop up to save that image to his desktop.

我曾尝试过

<a href ="path" > </a>

但它正在其他网页上打开形象,我希望用户能够拯救或观看图像,

帮助

预 收

最佳回答

你们需要再有一页,或者更确切地说,需要一个HttpHandler,把图像路作为盘点的一部分,或作为将发送到附件内容分层的答复的邮寄参数。 采用这种方式确定内容,将使浏览器能够显示文件下载方言。 稍微容易一些,尽管这取决于用户做额外的事情,但只是要把这个链接放在新网页上,让用户右翼插上,并做“Save As”。

<a href="/path/to/handler?image=name-of-image-file">Download</a>

<a href="/path/to/image" target="_blank">
    Load Image in New Window then Use Save As</a>
问题回答

页: 1 IHttpHandler ,与<代码>Content-Disposition一道为图像服务。

例如:

Response.AppendHeader("Content-Disposition", "attachment; filename="MyImage.png"");
Response.TransmitFile(path);

You would probably pass the image name on the query-string.
If so, make sure it doesn t contain / or , or attackers will be able to read arbitrary files.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签