由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。

Web攻城狮-前端 2012-04-10 10:07:40
今天在做一个下载功能的页面,出了这样的问题:
我从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();这里有异常:

由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。
各位大侠给看看吧。到底怎么回事?
...全文
1876 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
woshihai_2007 2012-08-17
  • 打赏
  • 举报
回复
方法一:在Response.Redirect后加return
方法二:使用重载函数Response.Redirect(String url, bool endResponse),例如:Response.Redirect ("nextpage.aspx", false)
方法三:调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法

woshihai_2007 2012-08-17
  • 打赏
  • 举报
回复
Response.Redirect(sURL, false);
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你说的这个不是程序本身的错误,而是说优化过的程序,调试器没有办法获得中间变量的值。

将编译方案设置为debug,再开启远程调试,才能进一步调试。
[/Quote]

请问,我在用Response.Redirect()进行跳转的时候会捕捉到一个异常,跟上面说的一样。并且跳转失败。不知道怎么回事,最后我才选择用Server.Execute与Server.Transfer()这两个方法,虽然跳转成功了。但是到下载页面并没有弹出下载对话框。请问这是上面原因,这个问题困扰我两天了。希望能帮我一下。我会加分的。
threenewbee 2012-04-10
  • 打赏
  • 举报
回复
你说的这个不是程序本身的错误,而是说优化过的程序,调试器没有办法获得中间变量的值。

将编译方案设置为debug,再开启远程调试,才能进一步调试。

62,240

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧