System.Threading.ThreadAbortException发生在mscorlib.dll中发生的历史persitently [英] System.Threading.ThreadAbortException occurred in mscorlib.dll occuring persitently

查看:229
本文介绍了System.Threading.ThreadAbortException发生在mscorlib.dll中发生的历史persitently的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进出口新的.NET,
使用以下code从gridview的IM转移到excel:

 保护无效toexcelbutton_Click(对象发件人,EventArgs的发送)
        {
       Response.ClearContent();
    将Response.Buffer =真;
    Response.AddHeader(内容处置的String.Format(附件;文件名= {0},attendancedatereport.xls));
    Response.ContentType =应用程序/ MS-Excel的;
    StringWriter的SW =新的StringWriter();
    HtmlTextWriter的HTW =新的HtmlTextWriter(SW);
    GridView1.AllowPaging = FALSE;
    GridView1.AllowSorting = FALSE;
    GridView1.DataBind();
    的HtmlForm htmfrm =新的HtmlForm();
    GridView1.Parent.Controls.Add(htmfrm);
    htmfrm.Attributes [RUNAT] =服务器;
    htmfrm.Controls.Add(GridView1);
    htmfrm.RenderControl(HTW);
    的Response.Write(sw.ToString());    HttpContext.Current.ApplicationInstance.CompleteRequest();
}

当我运行这个code,我得到一个异常:

类型'System.Threading.ThreadAbortException'的第一个机会异常出现在mscorlib.dll。

但是,当我在其他的页面相同的code另一个GridView控件,它完美的作品,我想,加入

  EnableEventValidation =假

要aspx页面,而

 < pre LANG =CS>公共覆盖无效VerifyRenderingInServerForm(控制控制)
{
   / *验证控件呈现* /
}< / pre>

到aspx.cs页面,

我试图清理临时文件,我仍然得到了同样的错误,超过5小时我都试过了,没有什么工作。

然后我试着选中调试 - > 例外菜单项,然后在出现的对话框中,选中第一个复选框为公共语言运行库异常,

我得到这个错误:


  

访问路径C:\\用户\\ ABCD \\应用程序数据\\本地\\ TEMP \\临时ASP.NET文件\\标志\\ 3f229106 \\ f785abea \\ App_Web_0h5ppn4m.dll'被拒绝



解决方案

是的,它会发生,由于这样的:

 到Response.End();

由于记录


  

要模仿ASP End方法的行为,这种方法试图提出一个[ThreadAbortException]例外。如果尝试成功,调用线程将被中止,这是不利于你的网站的性能。在这种情况下,呼叫到最终方法后无code为执行


所以你的 Response.Clear 通话是没有意义的 - 你应该的期望的看到 ThreadAbortException ,你可以在这种情况下忽略。

如果您需要调用 Response.Clear 所有的,它应该是你写之前 - 但我怀疑你没事只是删除它完全。

Im new to .net, Im using the following code to transfer from gridview to excel:

         protected void toexcelbutton_Click(object sender, EventArgs e)
        {
       Response.ClearContent();
    Response.Buffer = true;
    Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "attendancedatereport.xls"));
    Response.ContentType = "application/ms-excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    GridView1.AllowPaging = false;
    GridView1.AllowSorting = false;
    GridView1.DataBind();
    HtmlForm htmfrm = new HtmlForm();
    GridView1.Parent.Controls.Add(htmfrm);
    htmfrm.Attributes["runat"] = "server";
    htmfrm.Controls.Add(GridView1);
    htmfrm.RenderControl(htw);
    Response.Write(sw.ToString());

    HttpContext.Current.ApplicationInstance.CompleteRequest();
}

When i run this code,i get an exception:

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll.

But,when i run the same code in another page for another gridview,it works perfectly.,i tried,adding

EnableEventValidation="false"

to the aspx page, and

<pre lang="cs">public override void VerifyRenderingInServerForm(Control control)
{
   /* Verifies that the control is rendered */
}</pre>

to the aspx.cs page,

i tried clearing the temporary files, still i get the same error,for more than 5hours i have tried,nothing is working.

I then tried select the Debug -> Exceptions menu item, and in the dialog that appears, checked the first checkbox for "Common Language Runtime Exceptions,

i get this error:

Access to the path 'C:\Users\abcd\AppData\Local\Temp\Temporary ASP.NET Files\mark\3f229106\f785abea\App_Web_0h5ppn4m.dll' is denied.

解决方案

Yes, it will happen due to this:

Response.End();

As documented:

To mimic the behavior of the End method in ASP, this method tries to raise a [ThreadAbortException] exception. If this attempt is successful, the calling thread will be aborted, which is detrimental to your site's performance. In that case, no code after the call to the End method is executed.

So your Response.Clear call is pointless - and you should expect to see the ThreadAbortException, which you can ignore in this case.

If you need to call Response.Clear at all, it should be before you write to it - but I suspect you're fine to just remove it entirely.

这篇关于System.Threading.ThreadAbortException发生在mscorlib.dll中发生的历史persitently的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆