本文介绍了Response.End()抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好, 我正在尝试从gridview获取excel表。以下是我的代码: string excelXml = GetExcelXml(dsInput,filename); response.Clear(); response.AppendHeader(Content-Type,application / vnd.ms-excel); response.AppendHeader(Content-disposition,attachment; filename =+ filename); response.Write(excelXml); response.Flush(); response.End(); 我收到异常,因为[System.Threading.ThreadAbortException] = {Unable to评估表达式,因为代码已优化或本机框架位于调用堆栈之上。} 如果我删除response.End ()我没有看到异常。 response.End()的目的是什么?它为什么会抛出错误,我应该把它保存在我的代码中?解决方案 这是备用解决方案, System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(GetExcelXml(dsInput,filename)); response.Clear(); System.Web.HttpContext.Current.Response.AddHeader( Content-Disposition, attachment; filename = + fileName); response.Write(sb.ToString()); Response.End(); 希望这可以帮到你... http://forums.asp.net/t/984756.aspx/1 [ ^ ] Hello,I am trying to get excel sheet from gridview. Following is my code:string excelXml = GetExcelXml(dsInput, filename);response.Clear();response.AppendHeader("Content-Type", "application/vnd.ms-excel");response.AppendHeader("Content-disposition", "attachment;filename=" + filename);response.Write(excelXml);response.Flush();response.End();I am getting exception as "[System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}"If i remove response.End() i don't see the exception.What is purpose of response.End().. Why is it throwing error and should I keep it in my code? 解决方案 这篇关于Response.End()抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-01 16:02