下载.swf文件时的“保存"对话框 [英] Save dialog box when downloading a .swf file

查看:80
本文介绍了下载.swf文件时的“保存"对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们

我尝试使用下面的代码来显示单击.swf文件的链接时显示的保存对话框,但是问题是它不起作用.
任何人都可以共享代码以单击.swf文件扩展名单击链接时显示一个保存对话框.请查看下面的代码,我在htmlanchor click事件上调用它.让我知道是否还有其他解决方案..

Hi Guys

I am trying to use below code to show a save dialog box when a link with .swf file is clicked, But the problem is that its not working.
Can anyone share the code to show a save dialoge box when a link is clicked with .swf file extention. Please see the below code, I am calling it on htmlanchor click event. Let me know if there are any other soltions..

try
{
    HtmlAnchor anchor = (HtmlAnchor)sender;
    System.IO.FileInfo targetfile = new System.IO.FileInfo(anchor.HRef);

    if (targetfile.Exists)
    {
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + targetfile.Name);
        Response.AddHeader("Content-Length", targetfile.Length.ToString());
        Response.ContentType = "application/x-shockwave-flash";
        Response.WriteFile(targetfile.FullName);
    }
}
catch (Exception ex)
{
    LogException(ex);
}

推荐答案

我很高兴找到解决方案.顺便说一句,这可能会带来安全风险:
I''m glad you found a solution. By the way, this may be a security risk:
wajans写道:

System.IO.FileInfo targetfile = new System.IO.FileInfo(anchor.HRef);

System.IO.FileInfo targetfile = new System.IO.FileInfo(anchor.HRef);


如果有人入侵HTTP请求,他们可能会发回任意文件名(这将使他们可以访问您网站上几乎所有的文件,例如web.config).


If somebody hacks an HTTP request, they can potentially send back an arbitrary file name (which would give them access to pretty much any file on your website, such as the web.config).


您可以尝试:

You could try:

Response.ContentType "application/octet-stream"



祝你好运!



Good luck!


如果您不告诉我们很多不起作用"的信息,我们将为您提供帮助.

什么不起作用?您是否尝试在调试器下运行代码?
We can''t help you if you don''t tell us more than "it''s not working".

WHAT isn''t working? Did you try running the code under the debugger?


这篇关于下载.swf文件时的“保存"对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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