本文介绍了下载.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);
}

推荐答案

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).


Response.ContentType "application/octet-stream"



祝你好运!



Good luck!



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

07-22 21:58