今天在做一个下载功能的页面,出了这样的问题:
我从a页面用Server.Execute("b.aspx?value="+value);
b页面的代码如下:
 string  filePathStr = Page.Request["filePath"];
            List<string> filePathList = new List<string>();
            if (filePathStr != null && !string.IsNullOrEmpty(Request.QueryString["filePath"].ToString()))
            {
                filePathStr = filePathStr.ToString().Replace(@"$$", @"\");
                filePathList = filePathStr.Split('$').ToList();
            }
            string fileFolder = this.Request.PhysicalApplicationPath + "\\DownloadTemp\\" + string.Format("{0:yyyyMMddHHmms}", DateTime.Now);
            if (System.IO.Directory.Exists(fileFolder) == false)
            {
                System.IO.Directory.CreateDirectory(fileFolder);
            }
            foreach(string filePath in filePathList)
            {
                this.FileCopy(filePath, fileFolder);
            }            //压缩文件夹
            string[] FileProperties = new string[2];
            FileProperties[0] = fileFolder + "\\";
            FileProperties[1] = fileFolder + ".zip";
            if (FileProperties[0][FileProperties[0].Length - 1] != Path.DirectorySeparatorChar)
                FileProperties[0] += Path.DirectorySeparatorChar;
            ZipOutputStream s = new ZipOutputStream(File.Create(FileProperties[1]));
            s.SetLevel(6); // 0 - store only to 9 - means best compression
            zip(FileProperties[0], s, FileProperties[0]);
            s.Finish();
            s.Close();
            //删除临时文件夹
            this.DeleteFolder(fileFolder);
            //压缩文件下载
            try
            {
                FileInfo fileinfo = new FileInfo(fileFolder + ".zip");
                Response.Clear();
                Response.ClearHeaders();
                Response.Buffer = false;
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileinfo.Name, System.Text.Encoding.UTF8) + ";charset=GB2312");
                Response.AppendHeader("Content-Length", fileinfo.Length.ToString());
                Response.WriteFile(fileinfo.FullName);
                //HttpContext.Current.ApplicationInstance.CompleteRequest();
                Response.Flush();
                Response.End();
            }
            catch(Exception ex)
            {
                string message = ex.Message;
                Response.Flush();
                Response.End();
            }
            finally 
            {
                File.Delete(fileFolder + ".zip");
            }最终在Response.End();这里有异常:由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。
各位大侠给看看吧。到底怎么回事?

解决方案 »

  1.   

    你说的这个不是程序本身的错误,而是说优化过的程序,调试器没有办法获得中间变量的值。将编译方案设置为debug,再开启远程调试,才能进一步调试。
      

  2.   


    请问,我在用Response.Redirect()进行跳转的时候会捕捉到一个异常,跟上面说的一样。并且跳转失败。不知道怎么回事,最后我才选择用Server.Execute与Server.Transfer()这两个方法,虽然跳转成功了。但是到下载页面并没有弹出下载对话框。请问这是上面原因,这个问题困扰我两天了。希望能帮我一下。我会加分的。
      

  3.   

     Response.Redirect(sURL, false);
      

  4.   

    方法一:在Response.Redirect后加return
    方法二:使用重载函数Response.Redirect(String url, bool endResponse),例如:Response.Redirect ("nextpage.aspx", false)
    方法三:调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法