在ASP.NET中,通过主程序调用一个Download子页面,如以下代码所示,在XP系统中是正常的。 
但是在Windows Server 2003系统中,在Download页面中选择保存、正常保存后, 
在任务管理器的应用程序中会保留刚才的Download任务。 Download页面,像用IE下载文件相同的对话框,有打开,保存,取消三个按钮, 
打开和取消都没有问题,只有保存,任务才会残留在任务列表中。 求助:如何才能保存结束后关掉那个Download任务。 
是否需要进行什么特殊处理,或者是XP系统和2003的什么区别?       severPath = Session("SeverPath")        
      downLoadFile = New System.IO.FileInfo(filePath) 
                
        bufOutPut = Page.Response.BufferOutput.ToString 
      Page.Response.Clear()         Page.Response.AddHeader("Content-Disposition", "attachment;filename=" & _
            System.Web.HttpUtility.UrlEncode(downLoadFile.Name))
        Page.Response.AddHeader("Content-Length", downLoadFile.Length.ToString())        Page.Response.ContentType = "application/vnd.ms-excel" 
                
        Try 
            Page.Response.WriteFile(downLoadFile.FullName) 
        Catch ex As Exception 
          ...... 
        End Try         Page.Response.Write(bufOutPut) 
        Page.Response.End() 

解决方案 »

  1.   

    再说具体一点。做的这个程序是在Window Server 2003 上发布的。
    然后到不同的机器上远程访问,在Server2000 或者Server 2003 上出现关不掉空白页面的问题。在XP上调用,不会出现这个问题。
      

  2.   

    ......
    Response.ContentType = "application/force-download";
    Response.AddHeader("Content-Disposition", "attachment;filename="+fileName);
    Response.WriteFile(fullName);
    this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.close();</script>");
      

  3.   

    试验过Window.close()的,没有效果的。
    问题依旧。谢谢楼上的。。
      

  4.   

    谢谢楼上的。这个方法我也测试过了。第一次调用Download是可以的,问题没有再现。
    但是Download成功之后,页面就没有相应了。还是不行的。。
      

  5.   

    请参照我的代码        #region 下载文件
            /// <summary>
            /// 下载文件
            /// </summary>
            /// <param name="FilePath">文件路径</param>
            /// <param name="FileName">文件别名</param>
            public static void Download(string FilePath, string FileName)
            {
                if (string.IsNullOrEmpty(FilePath))
                {
                    return;
                }            if (FilePath.StartsWith("~"))
                {
                    FilePath = HttpContext.Current.Server.MapPath(FilePath);
                }
                if (!File.Exists(FilePath))
                {
                    // 文件不存在
                    HttpContext.Current.Response.Write("文件不存在");
                    return;
                }
                if (string.IsNullOrEmpty(FileName))
                {
                    FileName = System.IO.Path.GetFileName(FilePath);//原始文件名
                }
                else
                {
                    string Extension = System.IO.Path.GetExtension(FilePath);
                    if (!FileName.EndsWith(Extension))
                        FileName += Extension;
                }
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                //  文件名格式化
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; FileName=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
                HttpContext.Current.Response.TransmitFile(FilePath);
                HttpContext.Current.Response.End();
            }
            public static void Download(string FilePath)
            {
                Download(FilePath, string.Empty);
            }
            #endregion
      

  6.   

    以上代码不限制文件位于WEB根目录子目录下,也不要求IIS匿名用户有可读权限,只要求IIS执行用户或Web.config设置的本地用户有可读权限
      

  7.   

    FilePath参数需要注意的是,可用绝对路径(“X:\XXX.XXX”)或ASP.NET相对路径("~/Path/FileName"),当文件位于Web程序根目录以外,ASP.NET相对路径不可用
      

  8.   

    恩,我们的代码除了Response.TransmitFile 和 Response.WriteFile 就没有什么区别了。我们这里的是.NET1.1的,还没有装支持TransmitFile 的补丁的。我们现在做的是一个大工程,好像也不太好为了这一本程序去改这个的。。不过我先本机测试下,看看使用Response.TransmitFile能否解决这个问题。
      

  9.   

    在打开下载对话框的时候,有打开,保存和取消三个按键选择的,打开和取消都可以正常结束Download空白子页面,保存就不可以。点这三个按键的相应事件有什么区别呢?
      

  10.   

    试验过类似如下的代码,还是无效。
    System.IO.FileInfo file = new System.IO.FileInfo("F:\\mp3\\mp3\\别哭我最爱的人.mp3");
       Response.Clear();
       Response.ClearHeaders();
       Response.Buffer = false;
       Response.Charset="GB2312";
       Response.ContentEncoding=System.Text.Encoding.UTF8;
       Response.ContentType = "application/octet-stream";
       
       Response.AddHeader("Content-Disposition", "attachment; filename="+Server.UrlEncode("别哭我最爱的人.mp3"));
       Response.AddHeader("Content-Length", file.Length.ToString());      
       Response.WriteFile(file.FullName);
       Response.Flush();
       Response.End();
      

  11.   

    如果非要使用Download子页面或很喜欢这种方式,应从JS入手解决关闭窗口的问题
      

  12.   


    这个我也试过了。但是Download一次之后,主页面就不会有别的事件相应了。所以还是不行的啊。。
      

  13.   

    详细对比过Server机器和XP机器IE的设置,把Server机器的IE设置按照XP的设置了一遍,现象依然。应该也和IE设置没有多少关系了。
      

  14.   

    测试过,在ie7下面Download有时也会不成功的。。具体原因不祥。可能是安全原因之类的吧。