Thursday, March 22, 2012
Thread aborted when doing HttpContext.Current.Response.End
I have written a function to export the datagrid data to excel. In that
function I was calling HttpContext.Current.Response.End() at the end. If I a
m
doing this, I am getting an exception message "Thread was being aborted". If
I don't do this then it is exporting the whole data instead of just the
datagrid. I am not knowing what might be the problem. Please let me know if
you have any idea
Thnx,
Sridhar.That's just how Response.End() works, it throws a ThreadAbortExxception.
You can't doing anything wrong, but you may. You'll either need to handle
(catch/swallow/hide) the exception or change your page so only the grid
shows and there's no need to End the request.
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Sridhar" <Sridhar@.discussions.microsoft.com> wrote in message
news:92D1C4A0-006D-4DB7-87D3-86E26C8D0FD9@.microsoft.com...
> Hi,
> I have written a function to export the datagrid data to excel. In that
> function I was calling HttpContext.Current.Response.End() at the end. If I
> am
> doing this, I am getting an exception message "Thread was being aborted".
> If
> I don't do this then it is exporting the whole data instead of just the
> datagrid. I am not knowing what might be the problem. Please let me know
> if
> you have any idea
> Thnx,
> Sridhar.
Thread aborted when doing HttpContext.Current.Response.End
I have written a function to export the datagrid data to excel. In that
function I was calling HttpContext.Current.Response.End() at the end. If I am
doing this, I am getting an exception message "Thread was being aborted". If
I don't do this then it is exporting the whole data instead of just the
datagrid. I am not knowing what might be the problem. Please let me know if
you have any idea
Thnx,
Sridhar.That's just how Response.End() works, it throws a ThreadAbortExxception.
You can't doing anything wrong, but you may. You'll either need to handle
(catch/swallow/hide) the exception or change your page so only the grid
shows and there's no need to End the request.
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Sridhar" <Sridhar@.discussions.microsoft.com> wrote in message
news:92D1C4A0-006D-4DB7-87D3-86E26C8D0FD9@.microsoft.com...
> Hi,
> I have written a function to export the datagrid data to excel. In that
> function I was calling HttpContext.Current.Response.End() at the end. If I
> am
> doing this, I am getting an exception message "Thread was being aborted".
> If
> I don't do this then it is exporting the whole data instead of just the
> datagrid. I am not knowing what might be the problem. Please let me know
> if
> you have any idea
> Thnx,
> Sridhar.
thread being aborted?
Dim connstring As New SqlConnection("Server=kabunyawan\sqlexpress;Database=ojt;Trusted_Connection=True;")
Dim rs1 As New SqlDataAdapter("select * from wall where uname = '" & txtuname.Text & "' and pword = '" & txtpword.Text & "'", connstring)
Dim ds As New DataSet
Dim tmpStr As String
rs1.Fill(ds, "wall")
Try
tmpStr = ds.Tables("wall").Rows(0).Item("lvl")
If tmpStr = "admin" Then
Response.Redirect("contact.aspx")
Else
Response.Write(tmpStr)
Response.Write("admin")
Response.Write("1111111111111111")
End If
Catch ex As Exception
Response.Cookies("errmsg").Value = "Invalid username/password. Please contact the admins for assisstance."
Response.Redirect("merror.aspx")
End Try
End Sub
i am having error on response.redirect("contact.aspx").. but my other webforms are working..Problem Solved.. that error was caused by the "try-catch" part.. I've read that response.redirect will always give out an error if placed within a try-catch.. now i know!
Now read that Response.Write is a bad thing on ASP.NET pages. :)
Thread being aborted error message.
web systems, I keep getting an error message in some try...catch
statements that I've put in.
Error message is
Thread was being aborted
This is raised whenever a Response.Redirect was called."jediknight" <wakthar@.gmail.com> wrote in message
news:1186149498.280646.177860@.b79g2000hse.googlegroups.com...
> Having recently been asked to look into some bugs in one of our old
> web systems, I keep getting an error message in some try...catch
> statements that I've put in.
> Error message is
> Thread was being aborted
> This is raised whenever a Response.Redirect was called.
http://msdn2.microsoft.com/en-us/library/a8wa7sdt(vs.80).aspx
Mark Rae
ASP.NET MVP
http://www.markrae.net
this is normal, you can eat it.
Lit
"jediknight" <wakthar@.gmail.com> wrote in message
news:1186149498.280646.177860@.b79g2000hse.googlegroups.com...
> Having recently been asked to look into some bugs in one of our old
> web systems, I keep getting an error message in some try...catch
> statements that I've put in.
> Error message is
> Thread was being aborted
> This is raised whenever a Response.Redirect was called.
>
> this is normal, you can eat it.
you mean swallow right?
Regards,
Alvin Bruney
---
Shameless author plug
Excel Services for .NET is coming...
https://www.microsoft.com/MSPress/books/10933.aspx
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Lit" <sql_agentman@.hotmail.com> wrote in message
news:OsRGFAf1HHA.5992@.TK2MSFTNGP02.phx.gbl...
> this is normal, you can eat it.
> Lit
>
> "jediknight" <wakthar@.gmail.com> wrote in message
> news:1186149498.280646.177860@.b79g2000hse.googlegroups.com...
>
Thread being aborted error message.
web systems, I keep getting an error message in some try...catch
statements that I've put in.
Error message is
Thread was being aborted
This is raised whenever a Response.Redirect was called."jediknight" <wakthar@.gmail.comwrote in message
news:1186149498.280646.177860@.b79g2000hse.googlegr oups.com...
Quote:
Originally Posted by
Having recently been asked to look into some bugs in one of our old
web systems, I keep getting an error message in some try...catch
statements that I've put in.
Error message is
>
Thread was being aborted
>
This is raised whenever a Response.Redirect was called.
http://msdn2.microsoft.com/en-us/li...sdt(vs.80).aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
this is normal, you can eat it.
Lit
"jediknight" <wakthar@.gmail.comwrote in message
news:1186149498.280646.177860@.b79g2000hse.googlegr oups.com...
Quote:
Originally Posted by
Having recently been asked to look into some bugs in one of our old
web systems, I keep getting an error message in some try...catch
statements that I've put in.
Error message is
>
Thread was being aborted
>
This is raised whenever a Response.Redirect was called.
>
this is normal, you can eat it.
you mean swallow right?
--
Regards,
Alvin Bruney
----------------
Shameless author plug
Excel Services for .NET is coming...
https://www.microsoft.com/MSPress/books/10933.aspx
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Lit" <sql_agentman@.hotmail.comwrote in message
news:OsRGFAf1HHA.5992@.TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
this is normal, you can eat it.
>
Lit
>
>
"jediknight" <wakthar@.gmail.comwrote in message
news:1186149498.280646.177860@.b79g2000hse.googlegr oups.com...
Quote:
Originally Posted by
>Having recently been asked to look into some bugs in one of our old
>web systems, I keep getting an error message in some try...catch
>statements that I've put in.
>Error message is
>>
>Thread was being aborted
>>
>This is raised whenever a Response.Redirect was called.
>>
>
>
Tuesday, March 13, 2012
Thread was being aborted
When I do the Login using the code below I am getting the
System.Thread.ThreadAbortException(Thread was being abortefd) on the last
line of the below code i.e.
Response.RedirectFormsAuthentication.GetRedirectUrluID,isPersistent));
there is no original URL, therefore it is returning Default.aspx.
I don't know why I am getting the above exception.
private void ButtonLogin_Click(object sender, System.EventArgs e)
{
string sessionID = "";
string uID = txtUsername.Text;
string pwd = txtPassword.Text;
bool isPersistent = false; try
{
ESMLoginResultEnum loginResult = ESMSecurityModule.Login(uID, pwd, out
sessionID);
string userData = sessionID;
switch(loginResult)
{
case ESMLoginResultEnum.OK:
{
FormsAuthenticationTicket ticket = new
FormsAuthenticationTicket(1,uID,System.DateTime.Now,System.DateTime.Now.AddM
inutes(AUTH_TIMEOUT),isPersistent,userDa
ta,FormsAuthentication.FormsCookiePa
th);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new
HttpCookie(FormsAuthentication.FormsCookieName,encTicket);
cookie.Path = FormsAuthentication.FormsCookiePath;
// Create the cookie.
Response.Cookies.Add(cookie);
// Redirect back to original URL.
Response.Redirect(FormsAuthentication.GetRedirectUrl(uID,isPersistent));
break;
}
}
}
}
Regards,
EktaEnhar:
Response.Redirect("someUrl") always throws a threadAbort exception.
Response.Reidrect("someUrl") calls Response.Redirect("someUrl", true)
with true meaning "end the response". So Response.End() is called which
throws that exception.
If you want, you can avoid the error by doing Response.ReidrecT("someUrl",
false)
or you could swollow the exception in a try/catch
try{
Response.Redirect("someUrl")
}catch (ThreadAbortException ex){}
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"enahar" <enahar@.hotmail.com> wrote in message
news:e092bRsIFHA.3628@.TK2MSFTNGP15.phx.gbl...
> Hi,
> When I do the Login using the code below I am getting the
> System.Thread.ThreadAbortException(Thread was being abortefd) on the last
> line of the below code i.e.
> Response.RedirectFormsAuthentication.GetRedirectUrluID,isPersistent));
> there is no original URL, therefore it is returning Default.aspx.
>
> I don't know why I am getting the above exception.
>
>
> private void ButtonLogin_Click(object sender, System.EventArgs e)
> {
> string sessionID = "";
> string uID = txtUsername.Text;
> string pwd = txtPassword.Text;
>
> bool isPersistent = false; try
> {
> ESMLoginResultEnum loginResult = ESMSecurityModule.Login(uID, pwd, out
> sessionID);
> string userData = sessionID;
> switch(loginResult)
> {
> case ESMLoginResultEnum.OK:
> {
> FormsAuthenticationTicket ticket = new
>
FormsAuthenticationTicket(1,uID,System.DateTime.Now,System.DateTime.Now.AddM
inutes(AUTH_TIMEOUT),isPersistent,userDa
ta,FormsAuthentication.FormsCookiePa
th);
> // Encrypt the ticket.
> string encTicket = FormsAuthentication.Encrypt(ticket);
> HttpCookie cookie = new
> HttpCookie(FormsAuthentication.FormsCookieName,encTicket);
> cookie.Path = FormsAuthentication.FormsCookiePath;
> // Create the cookie.
> Response.Cookies.Add(cookie);
> // Redirect back to original URL.
> Response.Redirect(FormsAuthentication.GetRedirectUrl(uID,isPersistent));
>
> break;
> }
> }
> }
> }
>
> Regards,
> Ekta
>
>
Hi,
Session is still not timing out when there is no activity by the user for 15
minutes.
My web.config settings are as below.
also in the login page for the ticket I am adding 15 minutes.
What is wrong i am doing it..
Regards,
Ekta
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
uID,
System.DateTime.Now,
System.DateTime.Now.AddMinutes(15),
isPersistent,
userData,
FormsAuthentication.FormsCookiePath);
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="AppConfiguration" type="PIT.ESH.Common.WebConfiguration,
PITSHCommon" />
</configSections>
<system.web>
<compilation defaultLanguage="c#" debug="true" />
<customErrors mode="RemoteOnly" />
<authentication mode="Forms">
<forms loginUrl="Security/Login.aspx" protection="All" timeout="2" path="/"
/>
</authentication>
<authorization>
<deny users="?" />
</authorization>
<trace enabled="true" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false" timeout="2" />
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-AU"
uiCulture = "en-AU"
/>
</system.web>
<AppConfiguration>
<!-- Application Settings -->
<add key="Web.EnablePageCache" value="true" />
<add key="Web.PageCacheExpiresInSeconds" value="3600" />
<add key="Web.EnableSsl" value="False" />
<add key="DB.ConnectionString" value="Data Source=DEVTEST-SQL1;User
ID=sa;Password=;Initial Catalog=Genesis2" />
<add key="Copyright.Message" value=" 2001-04 Positive IT Solutions Pty
Ltd." />
<add key="Copyright.EMail" value="" />
</AppConfiguration>
<appSettings>
<add key="Copyright.EMail" value="Etivity@.Postitive-IT.com.au" />
</appSettings>
<system.runtime.remoting>
<application>
</application>
</system.runtime.remoting>
<location path="default.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="Security">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="Public">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
</configuration>
On Mon, 7 Mar 2005 17:09:01 +1100, "enahar" <enahar@.hotmail.com>
wrote:
>Hi,
>Session is still not timing out when there is no activity by the user for 1
5
>minutes.
>My web.config settings are as below.
>also in the login page for the ticket I am adding 15 minutes.
>
>What is wrong i am doing it..
>
>Regards,
>Ekta
>
Hi Etka:
Are you testing the Session timeout or the forms authentication ticket
timeout?
Scott
http://www.OdeToCode.com/blogs/scott/
I am writing the following code in the web.config file and the Login.aspx.cs
for the sessiopn TimeOut and for the forms authentication ticket timeout.
Also I am writing the following code in the Body tag of the Login.aspx page
<meta http-equiv="Refresh" URL="../Security/Login.aspx>
even then Session is still not timing out when there is no activity by the
user for 15 minutes.What is wrong I am doing it.Please suggest.
code in the session_end is as follows:
protected void Session_End(Object sender, EventArgs e)
{
FormsAuthentication.SignOut();
if (Session["SessionID"] != null)
{
try
{
ESMSecurityModule.killSession(Session["SessionID"].ToString());
}
catch
{
}
}
}
WEB.CONFIG
<authentication mode="Forms">
<forms loginUrl="../Security/Login.aspx" protection="All" timeout="15"
path="/" />
</authentication>
and for the forms authentication ticket TimeOut I am writing the following
code in the Login.aspx page:
LOGIN.ASPX PAGE
FormsAuthenticationTicket ticket = new
FormsAuthenticationTicket(1,uID,System.DateTime.Now,System.DateTime.Now.AddM
inutes(15),false,userData,FormsAuthentic
ation.FormsCookiePath);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new
HttpCookie(FormsAuthentication.FormsCookieName,encTicket);
cookie.Path = FormsAuthentication.FormsCookiePath;
// Create the cookie.
Response.Cookies.Add(cookie);
// Redirect back to original URL.
Response.Redirect(FormsAuthentication.GetRedirectUrl(uID,isPersistent),false
);
Regards,
Ekta
"Scott Allen" <scott@.nospam.odetocode.com> wrote in message
news:l3vo21hihtmb3pauqj9sphjqorb7v225fk@.
4ax.com...
> On Mon, 7 Mar 2005 17:09:01 +1100, "enahar" <enahar@.hotmail.com>
> wrote:
>
> Hi Etka:
> Are you testing the Session timeout or the forms authentication ticket
> timeout?
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
Hi enahar:
Don't relay on the Session_End event. Have you tested by hitting the
site with the browser after over 15 minutes of inactivity?
Scott
http://www.OdeToCode.com/blogs/scott/
Yes I have tested by hitting the
site with the browser after over 15 minutes of inactivity?
Regards
Ekta
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
Thread was being aborted
has me puzzled. I'm using the same very simple approach throughout the
application, and it works elsewhere:
-- my aspx form declares an instance of a data-layer class with form-level
scope
Protected WithEvents MyDataLayer as DataLayer
-- and a new instance of the class is created in Page_Load:
MyDataLayer = New DataLayer
AddHandler MyDataLayer.Success, AddressOf OnSuccess
-- on the aspx form, a Save button onclick eventhandler invokes a method in
the datalayer class
MyDataLayer.DoSomething()
-- the data layer's DoSomething() method executes a stored procedure against
SQL Server and raises either a Success or Failure event
RaiseEvent Success(args as DataLayer.SuccessArgs)
-- a subroutines on the aspx form listens for the success event:
Private Sub OnSuccess(args as DataLayer.SuccessArgs)
Try
'// on Success, we want to go to another page;
'// none of the following alternatives works:
Response.Redirect("SomeOtherPage.aspx", False)
Response.Redirect("SomeOtherPage.aspx", True)
Server.Transfer("SomeOtherPage.aspx", False)
Server.Transfer("SomeOtherPage.aspx", True)
Catch ex as Exception
'// always thread was being aborted error
End Try
End Sub
How do I fix this? Is it a timing issue not under programmer's control?
Thanks
K.Hi Josef:
ThreadAbortException is the expected behavior for
Response.Redirect(url, true) [1]. Are you still getting an abort when
passing false as the second parameter?
[1] http://support.microsoft.com/kb/312629/EN-US/
Scott
http://www.OdeToCode.com/blogs/scott/
On Sun, 22 May 2005 12:48:10 -0400, "Josef K." <josefk@.spamcastle.org>
wrote:
>I've started getting "Thread was being aborted" errors. This errormessage
>has me puzzled. I'm using the same very simple approach throughout the
>application, and it works elsewhere:
>-- my aspx form declares an instance of a data-layer class with form-level
>scope
>Protected WithEvents MyDataLayer as DataLayer
>-- and a new instance of the class is created in Page_Load:
>MyDataLayer = New DataLayer
>AddHandler MyDataLayer.Success, AddressOf OnSuccess
>-- on the aspx form, a Save button onclick eventhandler invokes a method in
>the datalayer class
>MyDataLayer.DoSomething()
>-- the data layer's DoSomething() method executes a stored procedure agains
t
>SQL Server and raises either a Success or Failure event
>RaiseEvent Success(args as DataLayer.SuccessArgs)
>-- a subroutines on the aspx form listens for the success event:
>Private Sub OnSuccess(args as DataLayer.SuccessArgs)
> Try
> '// on Success, we want to go to another page;
> '// none of the following alternatives works:
> Response.Redirect("SomeOtherPage.aspx", False)
> Response.Redirect("SomeOtherPage.aspx", True)
> Server.Transfer("SomeOtherPage.aspx", False)
> Server.Transfer("SomeOtherPage.aspx", True)
> Catch ex as Exception
> '// always thread was being aborted error
> End Try
>End Sub
>How do I fix this? Is it a timing issue not under programmer's control?
>Thanks
>K.
>
Thread was being aborted
I have an error mod in my app that emails me whenever there is an error. I
use try..catch to capture the error. It works great, I love it, except for
this one minor issue. Whenever there is a script that processes some data
then issues a response.redirect() I get "Thread was being aborted" emailed
to me. Below is an example of a script of where the error is occuring. It
doesn't affect the end user at all, but I just keep getting the emails and
I'm going live with this today, which means more emails :(
Try
sqlconn.Open()
If sqlcomm.ExecuteNonQuery > 0 Then
lblError.Text = ""
sqlconn.Close()
Response.Redirect("eventhotels.aspx?EID=" & EID)
Else
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
"nothing to update.")
End If
Catch ex As Exception
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
ex.Message)
End Try
I tried putting the sqlconn.close into the finally statement but still for
the same results.
Thanks!!
David Lozzi
Web Applications Developer
dlozzi@dotnet.itags.org.(remove-this)delphi-ts.comCatch the ThreadAbortException
Catch tae as System.Threading.ThreadAbortException
' ignore it.
Catch ex as Exception
' email the error
End Try
"David Lozzi" <DavidLozzi@.nospam.nospam> wrote in message
news:eTyw4PSHGHA.1032@.TK2MSFTNGP11.phx.gbl...
> Howdy,
> I have an error mod in my app that emails me whenever there is an error. I
> use try..catch to capture the error. It works great, I love it, except for
> this one minor issue. Whenever there is a script that processes some data
> then issues a response.redirect() I get "Thread was being aborted" emailed
> to me. Below is an example of a script of where the error is occuring. It
> doesn't affect the end user at all, but I just keep getting the emails and
> I'm going live with this today, which means more emails :(
> Try
> sqlconn.Open()
> If sqlcomm.ExecuteNonQuery > 0 Then
> lblError.Text = ""
> sqlconn.Close()
> Response.Redirect("eventhotels.aspx?EID=" & EID)
> Else
> sqlconn.Close()
> lblError.Text = EmailError("eventhoteladd", "savehotel",
> "nothing to update.")
> End If
> Catch ex As Exception
> sqlconn.Close()
> lblError.Text = EmailError("eventhoteladd", "savehotel",
> ex.Message)
> End Try
> I tried putting the sqlconn.close into the finally statement but still for
> the same results.
> Thanks!!
> --
> David Lozzi
> Web Applications Developer
> dlozzi@.(remove-this)delphi-ts.com
>
>
You can prevent this exception from being thrown by using the
overloaded version of Response.Redirect and passing False into the 2nd
parameter.
You are getting this exception because the Response.Redirect method
internally calls Response.End,which raises this exception and the page
processing terminates. Response.End raises the exception indirectly through
calling Thread.Abort. Move the redirect to outside of the Try block, and use
the "false" overload of Response.Redirect method:
Instead of putting Response.Redirect into a Try..Catch block. You may try
this one:
Dim redirect as Boolean =False;
Try
sqlconn.Open()
If sqlcomm.ExecuteNonQuery > 0 Then
lblError.Text = ""
sqlconn.Close()
Else
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
"nothing to update.")
End If
Catch ex As Exception
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
ex.Message)
End Try
If Redirect Then Response.Redirect("eventhotels.aspx?EID=" & EID, False)
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"David Lozzi" wrote:
> Howdy,
> I have an error mod in my app that emails me whenever there is an error. I
> use try..catch to capture the error. It works great, I love it, except for
> this one minor issue. Whenever there is a script that processes some data
> then issues a response.redirect() I get "Thread was being aborted" emailed
> to me. Below is an example of a script of where the error is occuring. It
> doesn't affect the end user at all, but I just keep getting the emails and
> I'm going live with this today, which means more emails :(
> Try
> sqlconn.Open()
> If sqlcomm.ExecuteNonQuery > 0 Then
> lblError.Text = ""
> sqlconn.Close()
> Response.Redirect("eventhotels.aspx?EID=" & EID)
> Else
> sqlconn.Close()
> lblError.Text = EmailError("eventhoteladd", "savehotel",
> "nothing to update.")
> End If
> Catch ex As Exception
> sqlconn.Close()
> lblError.Text = EmailError("eventhoteladd", "savehotel",
> ex.Message)
> End Try
> I tried putting the sqlconn.close into the finally statement but still for
> the same results.
> Thanks!!
> --
> David Lozzi
> Web Applications Developer
> dlozzi@.(remove-this)delphi-ts.com
>
>
>
thread was being aborted
Hi, everyone
I create one application with form authentication.
When I try to run application and press login button it will redirect to default page and application run success fully, some time it will not redirect to default page .
For my application, I have to create one txt log file for error …
Sometime this error occurs when I press login button….
--------------------------
Source Code : mscorlib
Error Message : Thread was being aborted.
Stack Trace : at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at System.Web.HttpResponse.Redirect(String url)
at pms._default.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\aspnet\pms\default.aspx.vb:line 104
--------------------------
source code for login button is……
--------------------------
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Try
singleSqlString = "SELECT emp_code,password,access_level,emp_name " & _
"FROM login_master " & _
"WHERE emp_code='" & txtEmpCode.Text & "' AND password='" & txtPassword.Text & "' " & _
"ORDER BY emp_code ASC"
objlogin.FillDataSet(singleSqlString, "login_master")
If objlogin.dtSet.Tables("login_master").Rows.Count > 0 Then
Session("LoginCode") = txtEmpCode.Text
Session("EmpName") = objlogin.dtSet.Tables("login_master").Rows(0).Item("emp_name")
Session("AccessLevel") = objlogin.dtSet.Tables("login_master").Rows(0).Item("access_level")
FormsAuthentication.RedirectFromLoginPage(txtEmpCode.Text, False)
Else
lblmsg.Text = " Employee Code or Password may be wrong. - Try Again !!"
txtEmpCode.Text = ""
txtPassword.Text = ""
End If
Catch ex As ThreadAbortException
lblmsg.Visible = True
lblmsg.Text = "Thread is aboard"
Catch ex As Exception
objlogin.CreateLogFile(ex, objlogin.Message)
End Try
End Sub
--------------------------
when I trace my application using break point exception is not generated , but error occurs
plz give any solution and cause for this error.
Thanks in advance
Hi,The error generated appears to be occuring on the default page:
at pms._default.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\aspnet\pms\default.aspx.vb:line 104
Have you checked/debugged the code here to see what's happening?Thread was being aborted
I have an ASPX page that does a Response.Redirect.
I get a message stating "Thread was being aborted".
The page I am redirecting to only have 2 lines of VB.
Anyone know why I am getting this error?
Thanks,
C.You may try "Response.Redirect ("aspxName.aspx",false)".
Thread was being aborted
When I do the Login using the code below I am getting the
System.Thread.ThreadAbortException(Thread was being abortefd) on the last
line of the below code i.e.
Response.RedirectFormsAuthentication.GetRedirectUr luID,isPersistent));
there is no original URL, therefore it is returning Default.aspx.
I don't know why I am getting the above exception.
private void ButtonLogin_Click(object sender, System.EventArgs e)
{
string sessionID = "";
string uID = txtUsername.Text;
string pwd = txtPassword.Text;
bool isPersistent = false; try
{
ESMLoginResultEnum loginResult = ESMSecurityModule.Login(uID, pwd, out
sessionID);
string userData = sessionID;
switch(loginResult)
{
case ESMLoginResultEnum.OK:
{
FormsAuthenticationTicket ticket = new
FormsAuthenticationTicket(1,uID,System.DateTime.No w,System.DateTime.Now.AddMinutes(AUTH_TIMEOUT),isP ersistent,userData,FormsAuthentication.FormsCookie Path);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new
HttpCookie(FormsAuthentication.FormsCookieName,enc Ticket);
cookie.Path = FormsAuthentication.FormsCookiePath;
// Create the cookie.
Response.Cookies.Add(cookie);
// Redirect back to original URL.
Response.Redirect(FormsAuthentication.GetRedirectU rl(uID,isPersistent));
break;
}
}
}
}
Regards,
EktaEnhar:
Response.Redirect("someUrl") always throws a threadAbort exception.
Response.Reidrect("someUrl") calls Response.Redirect("someUrl", true)
with true meaning "end the response". So Response.End() is called which
throws that exception.
If you want, you can avoid the error by doing Response.ReidrecT("someUrl",
false)
or you could swollow the exception in a try/catch
try{
Response.Redirect("someUrl")
}catch (ThreadAbortException ex){}
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"enahar" <enahar@.hotmail.com> wrote in message
news:e092bRsIFHA.3628@.TK2MSFTNGP15.phx.gbl...
> Hi,
> When I do the Login using the code below I am getting the
> System.Thread.ThreadAbortException(Thread was being abortefd) on the last
> line of the below code i.e.
> Response.RedirectFormsAuthentication.GetRedirectUr luID,isPersistent));
> there is no original URL, therefore it is returning Default.aspx.
>
> I don't know why I am getting the above exception.
>
>
> private void ButtonLogin_Click(object sender, System.EventArgs e)
> {
> string sessionID = "";
> string uID = txtUsername.Text;
> string pwd = txtPassword.Text;
>
> bool isPersistent = false; try
> {
> ESMLoginResultEnum loginResult = ESMSecurityModule.Login(uID, pwd, out
> sessionID);
> string userData = sessionID;
> switch(loginResult)
> {
> case ESMLoginResultEnum.OK:
> {
> FormsAuthenticationTicket ticket = new
FormsAuthenticationTicket(1,uID,System.DateTime.No w,System.DateTime.Now.AddM
inutes(AUTH_TIMEOUT),isPersistent,userData,FormsAu thentication.FormsCookiePa
th);
> // Encrypt the ticket.
> string encTicket = FormsAuthentication.Encrypt(ticket);
> HttpCookie cookie = new
> HttpCookie(FormsAuthentication.FormsCookieName,enc Ticket);
> cookie.Path = FormsAuthentication.FormsCookiePath;
> // Create the cookie.
> Response.Cookies.Add(cookie);
> // Redirect back to original URL.
> Response.Redirect(FormsAuthentication.GetRedirectU rl(uID,isPersistent));
>
> break;
> }
> }
> }
> }
>
> Regards,
> Ekta
>
Hi,
Session is still not timing out when there is no activity by the user for 15
minutes.
My web.config settings are as below.
also in the login page for the ticket I am adding 15 minutes.
What is wrong i am doing it..
Regards,
Ekta
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
uID,
System.DateTime.Now,
System.DateTime.Now.AddMinutes(15),
isPersistent,
userData,
FormsAuthentication.FormsCookiePath);
:
<?xml version="1.0" encoding="utf-8" ?
<configuration
<configSections
<section name="AppConfiguration" type="PIT.ESH.Common.WebConfiguration,
PITSHCommon" /
</configSections
<system.web
<compilation defaultLanguage="c#" debug="true" /
<customErrors mode="RemoteOnly" /
<authentication mode="Forms"
<forms loginUrl="Security/Login.aspx" protection="All" timeout="2" path="/"
/
</authentication
<authorization
<deny users="?" /
</authorization
<trace enabled="true" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" /
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false" timeout="2" /
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-AU"
uiCulture = "en-AU"
/
</system.web
<AppConfiguration
<!-- Application Settings --
<add key="Web.EnablePageCache" value="true" /
<add key="Web.PageCacheExpiresInSeconds" value="3600" /
<add key="Web.EnableSsl" value="False" /
<add key="DB.ConnectionString" value="Data Source=DEVTEST-SQL1;User
ID=sa;Password=;Initial Catalog=Genesis2" /
<add key="Copyright.Message" value=" 2001-04 Positive IT Solutions Pty
Ltd." /
<add key="Copyright.EMail" value="" /
</AppConfiguration
<appSettings
<add key="Copyright.EMail" value="Etivity@.Postitive-IT.com.au" /
</appSettings
<system.runtime.remoting
<application
</application
</system.runtime.remoting
<location path="default.aspx"
<system.web
<authorization
<allow users="?" /
</authorization
</system.web
</location
<location path="Security"
<system.web
<authorization
<allow users="?" /
</authorization
</system.web
</location
<location path="Public"
<system.web
<authorization
<allow users="*" /
</authorization
</system.web
</location
</configuration
On Mon, 7 Mar 2005 17:09:01 +1100, "enahar" <enahar@.hotmail.com>
wrote:
>Hi,
>Session is still not timing out when there is no activity by the user for 15
>minutes.
>My web.config settings are as below.
>also in the login page for the ticket I am adding 15 minutes.
>
>What is wrong i am doing it..
>
>Regards,
>Ekta
Hi Etka:
Are you testing the Session timeout or the forms authentication ticket
timeout?
--
Scott
http://www.OdeToCode.com/blogs/scott/
I am writing the following code in the web.config file and the Login.aspx.cs
for the sessiopn TimeOut and for the forms authentication ticket timeout.
Also I am writing the following code in the Body tag of the Login.aspx page
<meta http-equiv="Refresh" URL="../Security/Login.aspx
even then Session is still not timing out when there is no activity by the
user for 15 minutes.What is wrong I am doing it.Please suggest.
code in the session_end is as follows:
protected void Session_End(Object sender, EventArgs e)
{
FormsAuthentication.SignOut();
if (Session["SessionID"] != null)
{
try
{
ESMSecurityModule.killSession(Session["SessionID"].ToString());
}
catch
{
}
}
}
WEB.CONFIG
<authentication mode="Forms"
<forms loginUrl="../Security/Login.aspx" protection="All" timeout="15"
path="/" /
</authentication
and for the forms authentication ticket TimeOut I am writing the following
code in the Login.aspx page:
LOGIN.ASPX PAGE
FormsAuthenticationTicket ticket = new
FormsAuthenticationTicket(1,uID,System.DateTime.No w,System.DateTime.Now.AddMinutes(15),false,userDat a,FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new
HttpCookie(FormsAuthentication.FormsCookieName,enc Ticket);
cookie.Path = FormsAuthentication.FormsCookiePath;
// Create the cookie.
Response.Cookies.Add(cookie);
// Redirect back to original URL.
Response.Redirect(FormsAuthentication.GetRedirectU rl(uID,isPersistent),false);
Regards,
Ekta
"Scott Allen" <scott@.nospam.odetocode.com> wrote in message
news:l3vo21hihtmb3pauqj9sphjqorb7v225fk@.4ax.com...
> On Mon, 7 Mar 2005 17:09:01 +1100, "enahar" <enahar@.hotmail.com>
> wrote:
>>Hi,
>>
>>Session is still not timing out when there is no activity by the user for
>>15
>>minutes.
>>
>>My web.config settings are as below.
>>also in the login page for the ticket I am adding 15 minutes.
>>
>>
>>What is wrong i am doing it..
>>
>>
>>Regards,
>>Ekta
>>
>>
> Hi Etka:
> Are you testing the Session timeout or the forms authentication ticket
> timeout?
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
Hi enahar:
Don't relay on the Session_End event. Have you tested by hitting the
site with the browser after over 15 minutes of inactivity?
--
Scott
http://www.OdeToCode.com/blogs/scott/
Yes I have tested by hitting the
site with the browser after over 15 minutes of inactivity?
Regards
Ekta
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thread was being aborted
I have an error mod in my app that emails me whenever there is an error. I
use try..catch to capture the error. It works great, I love it, except for
this one minor issue. Whenever there is a script that processes some data
then issues a response.redirect() I get "Thread was being aborted" emailed
to me. Below is an example of a script of where the error is occuring. It
doesn't affect the end user at all, but I just keep getting the emails and
I'm going live with this today, which means more emails :(
Try
sqlconn.Open()
If sqlcomm.ExecuteNonQuery > 0 Then
lblError.Text = ""
sqlconn.Close()
Response.Redirect("eventhotels.aspx?EID=" & EID)
Else
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
"nothing to update.")
End If
Catch ex As Exception
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
ex.Message)
End Try
I tried putting the sqlconn.close into the finally statement but still for
the same results.
Thanks!!
--
David Lozzi
Web Applications Developer
dlozzi@dotnet.itags.org.(remove-this)delphi-ts.comCatch the ThreadAbortException
Catch tae as System.Threading.ThreadAbortException
' ignore it.
Catch ex as Exception
' email the error
End Try
"David Lozzi" <DavidLozzi@.nospam.nospam> wrote in message
news:eTyw4PSHGHA.1032@.TK2MSFTNGP11.phx.gbl...
> Howdy,
> I have an error mod in my app that emails me whenever there is an error. I
> use try..catch to capture the error. It works great, I love it, except for
> this one minor issue. Whenever there is a script that processes some data
> then issues a response.redirect() I get "Thread was being aborted" emailed
> to me. Below is an example of a script of where the error is occuring. It
> doesn't affect the end user at all, but I just keep getting the emails and
> I'm going live with this today, which means more emails :(
> Try
> sqlconn.Open()
> If sqlcomm.ExecuteNonQuery > 0 Then
> lblError.Text = ""
> sqlconn.Close()
> Response.Redirect("eventhotels.aspx?EID=" & EID)
> Else
> sqlconn.Close()
> lblError.Text = EmailError("eventhoteladd", "savehotel",
> "nothing to update.")
> End If
> Catch ex As Exception
> sqlconn.Close()
> lblError.Text = EmailError("eventhoteladd", "savehotel",
> ex.Message)
> End Try
> I tried putting the sqlconn.close into the finally statement but still for
> the same results.
> Thanks!!
> --
> David Lozzi
> Web Applications Developer
> dlozzi@.(remove-this)delphi-ts.com
>
You can prevent this exception from being thrown by using the
overloaded version of Response.Redirect and passing False into the 2nd
parameter.
You are getting this exception because the Response.Redirect method
internally calls Response.End,which raises this exception and the page
processing terminates. Response.End raises the exception indirectly through
calling Thread.Abort. Move the redirect to outside of the Try block, and use
the "false" overload of Response.Redirect method:
Instead of putting Response.Redirect into a Try..Catch block. You may try
this one:
Dim redirect as Boolean =False;
Try
sqlconn.Open()
If sqlcomm.ExecuteNonQuery > 0 Then
lblError.Text = ""
sqlconn.Close()
Else
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
"nothing to update.")
End If
Catch ex As Exception
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
ex.Message)
End Try
If Redirect Then Response.Redirect("eventhotels.aspx?EID=" & EID, False)
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"David Lozzi" wrote:
> Howdy,
> I have an error mod in my app that emails me whenever there is an error. I
> use try..catch to capture the error. It works great, I love it, except for
> this one minor issue. Whenever there is a script that processes some data
> then issues a response.redirect() I get "Thread was being aborted" emailed
> to me. Below is an example of a script of where the error is occuring. It
> doesn't affect the end user at all, but I just keep getting the emails and
> I'm going live with this today, which means more emails :(
> Try
> sqlconn.Open()
> If sqlcomm.ExecuteNonQuery > 0 Then
> lblError.Text = ""
> sqlconn.Close()
> Response.Redirect("eventhotels.aspx?EID=" & EID)
> Else
> sqlconn.Close()
> lblError.Text = EmailError("eventhoteladd", "savehotel",
> "nothing to update.")
> End If
> Catch ex As Exception
> sqlconn.Close()
> lblError.Text = EmailError("eventhoteladd", "savehotel",
> ex.Message)
> End Try
> I tried putting the sqlconn.close into the finally statement but still for
> the same results.
> Thanks!!
> --
> David Lozzi
> Web Applications Developer
> dlozzi@.(remove-this)delphi-ts.com
>
>
Thread was being aborted
first time user visits that page,in the below "GetData" is a method which
gets the data from SQL Server, but some times it is taking time to get data
and throwing this error i think it has to throw "Timed Out" instead of this
"Thread Abort" error. any idea why we get this error?
Exception Type: System.Threading.ThreadAbortException
ExceptionState: System.Web.HttpApplication+CancelModuleException
Message: Thread was being aborted.
TargetSite: System.Data.DataSet GetData(RPID,
System.Data.SqlClient.SqlCommand)Unless you post the full code around where the error happens, then I can
only guess. One common cause for this error is that you have a
Response.Redirect statement enclosed within a try...catch
--
[note: if this post answers your question, you can mark it as an answer
using the web-based newsreader functions]
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"xsluser" wrote:
> Any Idea why we get this error, its happening in only one page and that too
> first time user visits that page,in the below "GetData" is a method which
> gets the data from SQL Server, but some times it is taking time to get data
> and throwing this error i think it has to throw "Timed Out" instead of this
> "Thread Abort" error. any idea why we get this error?
> Exception Type: System.Threading.ThreadAbortException
> ExceptionState: System.Web.HttpApplication+CancelModuleException
> Message: Thread was being aborted.
> TargetSite: System.Data.DataSet GetData(RPID,
> System.Data.SqlClient.SqlCommand)
By default SQL Command has 30 second to finish.
If it did not finish then it's aborted.
Look at Command.CommandTimeout value and increase it.
George.
"xsluser" <xsluser@.discussions.microsoft.com> wrote in message news:F2E4E54F-7A47-47CE-BDC9-8FBDA9A9BD3F@.microsoft.com...
Any Idea why we get this error, its happening in only one page and that too
first time user visits that page,in the below "GetData" is a method which
gets the data from SQL Server, but some times it is taking time to get data
and throwing this error i think it has to throw "Timed Out" instead of this
"Thread Abort" error. any idea why we get this error?
Exception Type: System.Threading.ThreadAbortException
ExceptionState: System.Web.HttpApplication+CancelModuleException
Message: Thread was being aborted.
TargetSite: System.Data.DataSet GetData(RPID,
System.Data.SqlClient.SqlCommand)
thread was being aborted
response.end() to avoid HTML in the Excel document, I get an exception:
-----
An attempt to log the following error
failed:System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
------
Here's my code
Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedShasSql"),
connection1.conString)
da.Fill(ds, "ShasExcel")
Dim dt As DataTable = ds.Tables("ShasExcel")
'This code was dumping html into the spreadsheet
'Response.ContentType = "application/ms-excel"
'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
'Response.Write(ConvertDtToTDF(dt))
'This is the new code
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
Response.Clear()
Response.Write(ConvertDtToTDF(dt))
Response.End()
Catch ex As Exception
ExceptionManager.Publish(ex)
End Try
End Sub
Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
Try
Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer
'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next
Response.Write(vbCrLf)
'Output Data
For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next
Catch ex As Exception
ExceptionManager.Publish(ex)
End Try
End Function
_____
DC GGringo,
you might want to replace Response.End() with Response.Flush.
Let me know if this works for you.
Daniel Walzenbach
"DC Gringo" <dcgringo@.visiontechnology.net> schrieb im Newsbeitrag
news:OPF77XjjFHA.3348@.tk2msftngp13.phx.gbl...
>I have some code that creates and writes to an excel file. Right as I
>response.end() to avoid HTML in the Excel document, I get an exception:
> -----
> An attempt to log the following error
> failed:System.Threading.ThreadAbortException: Thread was being aborted.
> at System.Threading.Thread.AbortInternal()
> at System.Threading.Thread.Abort(Object stateInfo)
> at System.Web.HttpResponse.End()
> ------
> Here's my code
>
> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Try
> Dim ds As New DataSet
> Dim da As New SqlDataAdapter(Session("savedShasSql"),
> connection1.conString)
> da.Fill(ds, "ShasExcel")
> Dim dt As DataTable = ds.Tables("ShasExcel")
> 'This code was dumping html into the spreadsheet
> 'Response.ContentType = "application/ms-excel"
> 'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> 'Response.Write(ConvertDtToTDF(dt))
> 'This is the new code
> Response.ContentType = "application/ms-excel"
> Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> Response.Clear()
> Response.Write(ConvertDtToTDF(dt))
> Response.End()
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Sub
>
> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
> Try
> Dim dr As DataRow, ary() As Object, i As Integer
> Dim iCol As Integer
> 'Output Column Headers
> For iCol = 0 To dt.Columns.Count - 1
> Response.Write(dt.Columns(iCol).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> 'Output Data
> For Each dr In dt.Rows
> ary = dr.ItemArray
> For i = 0 To UBound(ary)
> Response.Write(ary(i).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> Next
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Function
> _____
> DC G
Daniel,
Sorry, it didn't work. I didn't get the error, but the HTML returned to the
Excel file. Putting the response.flush() after the response.close() or vice
versa still generated the error.
_____
DC G
"Daniel Walzenbach" <daniel.walzenbach@.newsgroup.nospam> wrote in message
news:%23u1QBEkjFHA.1148@.TK2MSFTNGP12.phx.gbl...
> Gringo,
> you might want to replace Response.End() with Response.Flush.
> Let me know if this works for you.
> Daniel Walzenbach
>
> "DC Gringo" <dcgringo@.visiontechnology.net> schrieb im Newsbeitrag
> news:OPF77XjjFHA.3348@.tk2msftngp13.phx.gbl...
>>I have some code that creates and writes to an excel file. Right as I
>>response.end() to avoid HTML in the Excel document, I get an exception:
>>
>> -----
>>
>> An attempt to log the following error
>> failed:System.Threading.ThreadAbortException: Thread was being aborted.
>> at System.Threading.Thread.AbortInternal()
>> at System.Threading.Thread.Abort(Object stateInfo)
>> at System.Web.HttpResponse.End()
>>
>> ------
>>
>> Here's my code
>>
>>
>> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
>> System.EventArgs)
>>
>> Try
>> Dim ds As New DataSet
>> Dim da As New SqlDataAdapter(Session("savedShasSql"),
>> connection1.conString)
>> da.Fill(ds, "ShasExcel")
>> Dim dt As DataTable = ds.Tables("ShasExcel")
>>
>> 'This code was dumping html into the spreadsheet
>> 'Response.ContentType = "application/ms-excel"
>> 'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
>> 'Response.Write(ConvertDtToTDF(dt))
>>
>> 'This is the new code
>> Response.ContentType = "application/ms-excel"
>> Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
>> Response.Clear()
>> Response.Write(ConvertDtToTDF(dt))
>> Response.End()
>>
>> Catch ex As Exception
>> ExceptionManager.Publish(ex)
>> End Try
>>
>> End Sub
>>
>>
>>
>> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
>>
>> Try
>>
>> Dim dr As DataRow, ary() As Object, i As Integer
>> Dim iCol As Integer
>>
>> 'Output Column Headers
>> For iCol = 0 To dt.Columns.Count - 1
>> Response.Write(dt.Columns(iCol).ToString & vbTab)
>> Next
>>
>> Response.Write(vbCrLf)
>>
>> 'Output Data
>>
>> For Each dr In dt.Rows
>> ary = dr.ItemArray
>> For i = 0 To UBound(ary)
>> Response.Write(ary(i).ToString & vbTab)
>> Next
>> Response.Write(vbCrLf)
>> Next
>>
>> Catch ex As Exception
>> ExceptionManager.Publish(ex)
>>
>> End Try
>>
>> End Function
>>
>> _____
>> DC G
>>
Yes, this is the way ASP.NET attempts to insure that the processing halts
for the current request -- they throw a ThreadAbortException. Sort of odd,
eh? Well, the magic with a ThreadAbortException is that if you put a try/catch
around it, it still gets thrown outside your catch -- they're doing this
so you don't catch their attempt to terminate the request. So, in short,
it's just how it works.
-Brock
DevelopMentor
http://staff.develop.com/ballen
> I have some code that creates and writes to an excel file. Right as I
> response.end() to avoid HTML in the Excel document, I get an
> exception:
> -----
> An attempt to log the following error
> failed:System.Threading.ThreadAbortException: Thread was being
> aborted.
> at System.Threading.Thread.AbortInternal()
> at System.Threading.Thread.Abort(Object stateInfo)
> at System.Web.HttpResponse.End()
> ------
> Here's my code
> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e
> As System.EventArgs)
> Try
> Dim ds As New DataSet
> Dim da As New SqlDataAdapter(Session("savedShasSql"),
> connection1.conString)
> da.Fill(ds, "ShasExcel")
> Dim dt As DataTable = ds.Tables("ShasExcel")
> 'This code was dumping html into the spreadsheet
> 'Response.ContentType = "application/ms-excel"
> 'Response.AddHeader("Content-Disposition",
> "inline;filename=shas.xls")
> 'Response.Write(ConvertDtToTDF(dt))
> 'This is the new code
> Response.ContentType = "application/ms-excel"
> Response.AddHeader("Content-Disposition",
> "inline;filename=shas.xls")
> Response.Clear()
> Response.Write(ConvertDtToTDF(dt))
> Response.End()
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Sub
> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
> Try
> Dim dr As DataRow, ary() As Object, i As Integer
> Dim iCol As Integer
> 'Output Column Headers
> For iCol = 0 To dt.Columns.Count - 1
> Response.Write(dt.Columns(iCol).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> 'Output Data
> For Each dr In dt.Rows
> ary = dr.ItemArray
> For i = 0 To UBound(ary)
> Response.Write(ary(i).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> Next
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Function
> _____
> DC G
a Response.End() does a flush, then kills the current thread (to stop
continued processing). ignore the thread abort in your catch
-- bruce (sqlwork.com)
"DC Gringo" <dcgringo@.visiontechnology.net> wrote in message
news:OPF77XjjFHA.3348@.tk2msftngp13.phx.gbl...
>I have some code that creates and writes to an excel file. Right as I
>response.end() to avoid HTML in the Excel document, I get an exception:
> -----
> An attempt to log the following error
> failed:System.Threading.ThreadAbortException: Thread was being aborted.
> at System.Threading.Thread.AbortInternal()
> at System.Threading.Thread.Abort(Object stateInfo)
> at System.Web.HttpResponse.End()
> ------
> Here's my code
>
> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Try
> Dim ds As New DataSet
> Dim da As New SqlDataAdapter(Session("savedShasSql"),
> connection1.conString)
> da.Fill(ds, "ShasExcel")
> Dim dt As DataTable = ds.Tables("ShasExcel")
> 'This code was dumping html into the spreadsheet
> 'Response.ContentType = "application/ms-excel"
> 'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> 'Response.Write(ConvertDtToTDF(dt))
> 'This is the new code
> Response.ContentType = "application/ms-excel"
> Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> Response.Clear()
> Response.Write(ConvertDtToTDF(dt))
> Response.End()
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Sub
>
> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
> Try
> Dim dr As DataRow, ary() As Object, i As Integer
> Dim iCol As Integer
> 'Output Column Headers
> For iCol = 0 To dt.Columns.Count - 1
> Response.Write(dt.Columns(iCol).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> 'Output Data
> For Each dr In dt.Rows
> ary = dr.ItemArray
> For i = 0 To UBound(ary)
> Response.Write(ary(i).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> Next
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Function
> _____
> DC G
Thread was being aborted
first time user visits that page,in the below "GetData" is a method which
gets the data from SQL Server, but some times it is taking time to get data
and throwing this error i think it has to throw "Timed Out" instead of this
"Thread Abort" error. any idea why we get this error?
Exception Type: System.Threading.ThreadAbortException
ExceptionState: System.Web.HttpApplication+CancelModuleException
Message: Thread was being aborted.
TargetSite: System.Data.DataSet GetData(RPID,
System.Data.SqlClient.SqlCommand)Unless you post the full code around where the error happens, then I can
only guess. One common cause for this error is that you have a
Response.Redirect statement enclosed within a try...catch
[note: if this post answers your question, you can mark it as an answer
using the web-based newsreader functions]
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"xsluser" wrote:
> Any Idea why we get this error, its happening in only one page and that to
o
> first time user visits that page,in the below "GetData" is a method which
> gets the data from SQL Server, but some times it is taking time to get dat
a
> and throwing this error i think it has to throw "Timed Out" instead of thi
s
> "Thread Abort" error. any idea why we get this error?
> Exception Type: System.Threading.ThreadAbortException
> ExceptionState: System.Web.HttpApplication+CancelModuleException
> Message: Thread was being aborted.
> TargetSite: System.Data.DataSet GetData(RPID,
> System.Data.SqlClient.SqlCommand)
By default SQL Command has 30 second to finish.
If it did not finish then it's aborted.
Look at Command.CommandTimeout value and increase it.
George.
"xsluser" <xsluser@.discussions.microsoft.com> wrote in message news:F2E4E54F
-7A47-47CE-BDC9-8FBDA9A9BD3F@.microsoft.com...
Any Idea why we get this error, its happening in only one page and that too
first time user visits that page,in the below "GetData" is a method which
gets the data from SQL Server, but some times it is taking time to get data
and throwing this error i think it has to throw "Timed Out" instead of this
"Thread Abort" error. any idea why we get this error?
Exception Type: System.Threading.ThreadAbortException
ExceptionState: System.Web.HttpApplication+CancelModuleException
Message: Thread was being aborted.
TargetSite: System.Data.DataSet GetData(RPID,
System.Data.SqlClient.SqlCommand)
Thread was being aborted
I have a login page, and after i validate a username and password i use a
response.redirect to the default page. The username and password are stored
in an sql db. In the response.redirect i use some session variables to be
added in the query string. However i am getting a "Thread was being
aborted.". Any ideas why this could happen?
Thanks inadvance.hi
You should not include the code "Response.redirect.. " in the code blok
"Try {} catch{}"
Sample:
try
{
//deal with the login logic
}
catch(Exception e)
{
}
Response.redirect("default.aspx");
Thanks a lot, it worked. But out of curiosity, you know why the error was
raised' what goes through the try-catch block that raised that error?
"Solo" <sunsolo@.gmail.com> wrote in message
news:1125819246.425176.236590@.z14g2000cwz.googlegroups.com...
> hi
> You should not include the code "Response.redirect.. " in the code blok
> "Try {} catch{}"
> Sample:
> try
> {
> //deal with the login logic
> }
> catch(Exception e)
> {
> }
> Response.redirect("default.aspx");
>
"Loui Mercieca" <loui@.destiny-creations.com> wrote in message
news:%23p3c7USsFHA.1132@.TK2MSFTNGP10.phx.gbl...
> Thanks a lot, it worked. But out of curiosity, you know why the error was
> raised' what goes through the try-catch block that raised that error?
It's a fairly common "gotcha". If you'd written:
Response.Redirect("default.aspx", false);
you wouldn't have got the error...
Loui,
this is what happens:
"The Response.End method ends the page execution and shifts the execution to
the Application_EndRequest event in the application's event pipeline. The
line of code that follows Response.End is not executed.
This problem occurs in the Response.Redirect and Server.Transfer methods
because both methods call Response.End internally. "
This behavior is by design. You can read about it in
http://support.microsoft.com/default.aspx?scid=kb;[LN];312629
Does this information help you?
Daniel Walzenbach
"Loui Mercieca" <loui@.destiny-creations.com> schrieb im Newsbeitrag
news:OvrjmBSsFHA.3504@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I have a login page, and after i validate a username and password i use a
> response.redirect to the default page. The username and password are
> stored in an sql db. In the response.redirect i use some session variables
> to be added in the query string. However i am getting a "Thread was being
> aborted.". Any ideas why this could happen?
> Thanks inadvance.
>
Thread was being aborted
"Thread was being aborted"
any body know how can i know what the problem is.
Best regards.
WafiNETAre you using Try/Catch blocks? If so, do you have a Response.Redirect inside a Catch block?
Yes, Iam uisng Try Catch and i am using Respone.Redirect
Thread was being aborted
I am getting an exception
when i print e.message it is::'Thread was being aborted.'
e.stacktrace is:: at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url, Boolean endResponse) at System.Web.HttpResponse.Redirect(String url) at EmailMessage.BtnSendMail_Click(Object sender, EventArgs e)'
what should i do?
Hey,
With your Response.Redirect statement, make it Response.Redirect("url destination", false);
Hi sujithukvl,
"thread was being aborted" is an known issue. you can find more detailed information by clicking the following links.
http://communityserver.org/forums/p/475527/556989.aspx
http://www.msdner.com/forum/thread261068.html
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic3899.aspx
This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
Thread was being aborted
has me puzzled. I'm using the same very simple approach throughout the
application, and it works elsewhere:
-- my aspx form declares an instance of a data-layer class with form-level
scope
Protected WithEvents MyDataLayer as DataLayer
-- and a new instance of the class is created in Page_Load:
MyDataLayer = New DataLayer
AddHandler MyDataLayer.Success, AddressOf OnSuccess
-- on the aspx form, a Save button onclick eventhandler invokes a method in
the datalayer class
MyDataLayer.DoSomething()
-- the data layer's DoSomething() method executes a stored procedure against
SQL Server and raises either a Success or Failure event
RaiseEvent Success(args as DataLayer.SuccessArgs)
-- a subroutines on the aspx form listens for the success event:
Private Sub OnSuccess(args as DataLayer.SuccessArgs)
Try
'// on Success, we want to go to another page;
'// none of the following alternatives works:
Response.Redirect("SomeOtherPage.aspx", False)
Response.Redirect("SomeOtherPage.aspx", True)
Server.Transfer("SomeOtherPage.aspx", False)
Server.Transfer("SomeOtherPage.aspx", True)
Catch ex as Exception
'// always thread was being aborted error
End Try
End Sub
How do I fix this? Is it a timing issue not under programmer's control?
Thanks
K.Hi Josef:
ThreadAbortException is the expected behavior for
Response.Redirect(url, true) [1]. Are you still getting an abort when
passing false as the second parameter?
[1] http://support.microsoft.com/kb/312629/EN-US/
--
Scott
http://www.OdeToCode.com/blogs/scott/
On Sun, 22 May 2005 12:48:10 -0400, "Josef K." <josefk@.spamcastle.org>
wrote:
>I've started getting "Thread was being aborted" errors. This errormessage
>has me puzzled. I'm using the same very simple approach throughout the
>application, and it works elsewhere:
>-- my aspx form declares an instance of a data-layer class with form-level
>scope
>Protected WithEvents MyDataLayer as DataLayer
>-- and a new instance of the class is created in Page_Load:
>MyDataLayer = New DataLayer
>AddHandler MyDataLayer.Success, AddressOf OnSuccess
>-- on the aspx form, a Save button onclick eventhandler invokes a method in
>the datalayer class
>MyDataLayer.DoSomething()
>-- the data layer's DoSomething() method executes a stored procedure against
>SQL Server and raises either a Success or Failure event
>RaiseEvent Success(args as DataLayer.SuccessArgs)
>-- a subroutines on the aspx form listens for the success event:
>Private Sub OnSuccess(args as DataLayer.SuccessArgs)
> Try
> '// on Success, we want to go to another page;
> '// none of the following alternatives works:
> Response.Redirect("SomeOtherPage.aspx", False)
> Response.Redirect("SomeOtherPage.aspx", True)
> Server.Transfer("SomeOtherPage.aspx", False)
> Server.Transfer("SomeOtherPage.aspx", True)
> Catch ex as Exception
> '// always thread was being aborted error
> End Try
>End Sub
>How do I fix this? Is it a timing issue not under programmer's control?
>Thanks
>K.
Thread was being aborted error message
a person clicks on a link in a datagrid.
In the event handler inside the parent page I construct a url to redirect to
containing information sent from the datagrid.
It all works fine on my local machine but when I send it to the live server
I receive "The thread was being aborted"
Doing some googling suggested that I use
Response.Redirect("./myurl.aspx?ID=" + variable,false);
to allow the current thread to continue executing.
This stops the error but what I am now finding is that the redirect does not
have the querystring attributes attached to it..
e.g. instead of looking like this...
http://www.website.com/myurl.aspx?ID=5
it looks like
http://www.website.com/myurl.aspx
It's like the redirect *never* happens...
Help appreciated
Thanks
MarkPut your Response.Redirect back to the way it was, without the false
parameter.
Then wrap it in a Try/Catch statement to eat the error that's raised from
the redirect.
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Jimi" <dontspam@.me.com> wrote in message
news:uls70dBXGHA.1352@.TK2MSFTNGP05.phx.gbl...
> Hi all, I have a user control which raises an event to the parent page
> when a person clicks on a link in a datagrid.
> In the event handler inside the parent page I construct a url to redirect
> to containing information sent from the datagrid.
> It all works fine on my local machine but when I send it to the live
> server I receive "The thread was being aborted"
> Doing some googling suggested that I use
> Response.Redirect("./myurl.aspx?ID=" + variable,false);
> to allow the current thread to continue executing.
> This stops the error but what I am now finding is that the redirect does
> not have the querystring attributes attached to it..
> e.g. instead of looking like this...
> http://www.website.com/myurl.aspx?ID=5
> it looks like
> http://www.website.com/myurl.aspx
>
> It's like the redirect *never* happens...
> Help appreciated
> Thanks
> Mark
>
>
Hi Steve, you mean like this?
try
{
Response.Redirect("./myurl.aspx?ID=" + variable);
}catch (Exception ex)
{
}
I have seen other people say take the Response.Redirect("./myurl.aspx?ID=" +
variable,false) out of the try catch block...
I understand why this is hapenning but cannot understand how to fix it...
Thanks again Steve..
Cheers
Mark
"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
news:eaqxRZEXGHA.3660@.TK2MSFTNGP04.phx.gbl...
> Put your Response.Redirect back to the way it was, without the false
> parameter.
> Then wrap it in a Try/Catch statement to eat the error that's raised from
> the redirect.
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
> "Jimi" <dontspam@.me.com> wrote in message
> news:uls70dBXGHA.1352@.TK2MSFTNGP05.phx.gbl...
>
Yes, that's what I'm suggesting. Does it work for you?
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Jimi" <dontspam@.me.com> wrote in message
news:efW%23QfEXGHA.4324@.TK2MSFTNGP03.phx.gbl...
> Hi Steve, you mean like this?
> try
> {
> Response.Redirect("./myurl.aspx?ID=" + variable);
> }catch (Exception ex)
> {
> }
> I have seen other people say take the Response.Redirect("./myurl.aspx?ID="
> + variable,false) out of the try catch block...
> I understand why this is hapenning but cannot understand how to fix it...
> Thanks again Steve..
> Cheers
> Mark
> "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
> news:eaqxRZEXGHA.3660@.TK2MSFTNGP04.phx.gbl...
>
Hi Steve, no unfortunately not.
I did a try catch and caught the exception like so:
catch (Exception ex)
Output of ex.Message was Thread was being aborted.
and ex.Source = mscorlib
Thanks again for your help
Cheers
Mark
"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
news:OlCNUwFXGHA.3848@.TK2MSFTNGP05.phx.gbl...
> Yes, that's what I'm suggesting. Does it work for you?
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
> "Jimi" <dontspam@.me.com> wrote in message
> news:efW%23QfEXGHA.4324@.TK2MSFTNGP03.phx.gbl...
>
Hi all, in the end due to time constraints I used a JavaScript redirect and
now it all works fine.
Thanks for your help Steve :)
Cheers
Mark
"Jimi" <dontspam@.me.com> wrote in message
news:uq2px$FXGHA.752@.TK2MSFTNGP02.phx.gbl...
> Hi Steve, no unfortunately not.
> I did a try catch and caught the exception like so:
> catch (Exception ex)
> Output of ex.Message was Thread was being aborted.
> and ex.Source = mscorlib
> Thanks again for your help
> Cheers
> Mark
>
>
> "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
> news:OlCNUwFXGHA.3848@.TK2MSFTNGP05.phx.gbl...
>