locked
Getting 'Thread was being aborted.' during the login process RRS feed

  • Question

  • User1256154619 posted

    I am dealing with a strange issue. Our code has a login process that, if the login is successful, forces to redirect the user to a home page.

    That logic works fine locally, on the test server, on the dev servers, and in production. However, just in one environment that process doesn't work. It is throwing the following exception

    Thread was being aborted. at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.AbortCurrentThread() at System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent) at System.Web.HttpResponse.Redirect(String url) at DRMS.login.Page_Load(Object sender, EventArgs e) in login.aspx.cs:line 116

    That is extremely strange at the line 116 point just to a bracket. Can somebody please help me with code? Thank you all in advance

    Down below I pasting an entire method including all lines

    24 protected void Page_Load(object sender, EventArgs e)
    25 {
    26
    27 try
    28 {
    29
    30 //DateTime warningDateTime = new DateTime();
    31 DataSet dset = null;
    32 drmsda = new DRMS_Transaction.drms_dataaccess();
    33
    34 //Changing Web.Config variables to DB Variables
    35 dset = drmsda.GetConfigVariables("Warning_Message");
    36 if (dset.Tables["ConfigVariables"] != null)
    37 {
    38 if (dset.Tables["ConfigVariables"].Rows.Count > 0)
    39 {
    40 if (dset.Tables["ConfigVariables"].Rows[0]["a_expiry"].ToString() != "")
    41 {
    42 if (Convert.ToDateTime(dset.Tables["ConfigVariables"].Rows[0]["a_expiry"]) >= Convert.ToDateTime(drmsda.GetServerDateTime()))
    43 {
    44 lblWarningMessage.Visible = true;
    45 lblWarningMessage.Text = dset.Tables["ConfigVariables"].Rows[0]["a_value"].ToString();
    46 }
    47
    48 }
    49 }
    50 }
    51
    52 if (!IsPostBack)
    53 {
    54 if (ConfigurationManager.AppSettings["InTestingMode"].ToUpper() == "YES")
    55 {
    56 txtUsername.Text = "kommulas@gmail.com";
    57 chkAgreement.Checked = true;
    58 }
    59
    60 //Changing Web.Config variables to Announcement
    61 dset = drmsda.GetConfigVariables("Announcement");
    62 if (dset.Tables["ConfigVariables"] != null)
    63 {
    64 if (dset.Tables["ConfigVariables"].Rows.Count > 0)
    65 {
    66 if (dset.Tables["ConfigVariables"].Rows[0]["a_expiry"].ToString() != "")
    67 {
    68 if (Convert.ToDateTime(dset.Tables["ConfigVariables"].Rows[0]["a_expiry"]) >= Convert.ToDateTime(drmsda.GetServerDateTime()))
    69 {
    70 lnkAnnouncement.Visible = true;
    71 lnkAnnouncement.Text = dset.Tables["ConfigVariables"].Rows[0]["a_value"].ToString();
    72 lnkAnnouncement.NavigateUrl = dset.Tables["ConfigVariables"].Rows[0]["a_url"].ToString();
    73 }
    74
    75 }
    76 }
    77 }
    78
    79 //Changing Web.Config variables to variables in database
    80 dset = drmsda.GetConfigVariables("OutageMessage");
    81 if (dset.Tables["ConfigVariables"] != null)
    82 {
    83 if (dset.Tables["ConfigVariables"].Rows.Count > 0)
    84 {
    85 if (dset.Tables["ConfigVariables"].Rows[0]["a_expiry"].ToString() != "")
    86 {
    87 if (Convert.ToDateTime(dset.Tables["ConfigVariables"].Rows[0]["a_expiry"]) >= Convert.ToDateTime(drmsda.GetServerDateTime()))
    88 {
    89 lblOutage.Visible = true;
    90
    91 lblOutage.Text = dset.Tables["ConfigVariables"].Rows[0]["a_value"].ToString();
    92 }
    93
    94 }
    95 }
    96 }
    97 //if (ConfigurationManager.AppSettings["TurnOnOutageMessage"].ToUpper() == "YES")
    98 //{
    99 // lblOutage.Visible = true;
    100 // lblLineBreak.Visible = true;
    101
    102 // lblOutage.Text = ConfigurationManager.AppSettings["OutageMessage"] + "  ";
    103 //}
    104
    105 string refererURL = string.Empty;
    106 if (Page.Request.QueryString["ReturnURL"] != null)
    107 {
    108 refererURL = Page.Request.QueryString["ReturnURL"].ToString();
    109 }
    110 //Check to see if user was redirected because of Timeout or initial login
    111 //Where "Default.aspx" is the default page for your application
    112 if (refererURL != "" && refererURL != (ResolveUrl("~") + "login.aspx"))
    113 {
    114 //Show HTML etc showing session timeout message
    115 if (refererURL == "/")
    116 {
    117 Response.Redirect("~/login.aspx", false);
    118 Context.ApplicationInstance.CompleteRequest();
    119 }
    120 else if (refererURL.Length >= 26)
    121 {
    122 if (refererURL.Substring(0, 26).ToLower() == "/public/searchresults.aspx")
    123 {
    124 Response.Redirect("~/login.aspx", false);
    125 Context.ApplicationInstance.CompleteRequest();
    126 }
    127 }
    128 else
    129 {
    130 drmsda.InsertErrorlog("External: login.aspx.cs", "Page Load", refererURL, refererURL, "");
    131 lblMessage.Text = "Session Timeout. Please login again.";
    132 lblMessage.Visible = true;
    133 }
    134 }
    135 //else
    136 //// User redirected here to to initial login
    137 //{
    138 // lblMessage.Text = "Please login";
    139 // lblMessage.Visible = true;
    140
    141 // //Show HTML showing initial login HTML message etc
    142 //}
    143
    144#if (SkipVirusCheck)
    145 Label2.Text = "ACCESS Application is running in Pilot Mode.<br><br>";
    146 //Label2.Text = "ACCESS Application is running in Debug Mode.<br><br>";
    147 //btnLogin.Text = "Debug Mode";
    148 //btnLogin.BackColor = Color.Red;
    149#endif
    150
    151 if (ConfigurationManager.AppSettings["IsSiteDown"].ToUpper() == "YES")
    152 {
    153 Response.Redirect("~/Message.aspx", false);
    154 Context.ApplicationInstance.CompleteRequest();
    155 }
    156 else
    157 {
    158
    159 //Changing Web.Config variables to variables in database
    160 dset = drmsda.GetConfigVariables("View_Notice_Label_1");
    161 if (dset.Tables["ConfigVariables"] != null)
    162 {
    163 if (dset.Tables["ConfigVariables"].Rows.Count > 0)
    164 {
    165 HyperLink7.Text = dset.Tables["ConfigVariables"].Rows[0]["a_value"].ToString();
    166 HyperLink7.NavigateUrl = dset.Tables["ConfigVariables"].Rows[0]["a_url"].ToString();
    167 HyperLinkMessage.Text = dset.Tables["ConfigVariables"].Rows[0]["a_value"].ToString();
    168 HyperLinkMessage.NavigateUrl = dset.Tables["ConfigVariables"].Rows[0]["a_url"].ToString();
    169 }
    170 }
    171 }
    172 }
    173 }
    174 catch (Exception e3)
    175 {
    176 drmsda.InsertErrorlog("External: login.aspx.cs", "Page Load", e3.Source, e3.Message + " " + e3.StackTrace, "");
    177 }
    178 }

    Wednesday, September 4, 2019 6:45 PM

Answers

  • User1256154619 posted

    Our team was able to find a solution

    The error itself was very deceptive and irrelevant. The problem lied in the Authentication settings in the IIS

    Went to our website, chose Features View -> Authentication -> Forms Authentication

    Make sure that 'Requires SSL' is unchecked

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 12, 2019 2:48 PM

All replies

  • User665608656 posted

    Hi mpodolski,

    Thread was being aborted. at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.AbortCurrentThread() at System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent) at System.Web.HttpResponse.Redirect(String url) at DRMS.login.Page_Load(Object sender, EventArgs e) in login.aspx.cs:line 116

    For this error message, it shows that this exception is throw by the call to Server.Transfer in order to halt the execution of the current method - exactly the same thing gets thrown if you do Response.Redirect.

    You can have two choices to solve this issue:

    • Catch and rethrow the ThreadAbortException / reperform the Server.Transfer.
    • Make sure that you only do Server.Transfer in places where it wont be caught (recommended)

    You could also refer to this link :

    PRB: System.Threading.ThreadAbortException Error Message When You Use Server.Transfer in HTTPHandler in an ASP.NET Application

    Best Regards,

    YongQing.

    Thursday, September 5, 2019 5:26 AM
  • User1256154619 posted

    Thank you very much for your reply. I will try this solution today. May I please ask you another question?

    As I mentioned earlier, the same code works in all environments but one. What would make a difference environment-wise? Can it be a setting within the IIS?

    Once again, thank you for your help

    Thursday, September 5, 2019 2:15 PM
  • User753101303 posted

    Hi,

    What I find strange is that you all your redirect have 2 arguments (which shouldn't throw) while the error message shows a single parameter (and yes it does through this exception to stop execution).

    Are you 100% sure you have the same code there as well ?

    Thursday, September 5, 2019 3:57 PM
  • User1256154619 posted

    Thank you very much for your reply and an attempt to help

    Yes, that is the very code. I know that because when change 'Response.Redirect' with 'Server.Execute' or 'Server.Transfer' I get a different behavior. 

    And once again, I am puzzled because I don't ever deal with that issue on any other environments (Dev, Test, production)

    Can it be an environment-related issue or IIS-related?

    Thursday, September 5, 2019 4:58 PM
  • User665608656 posted

    Hi mpodolski,

    I found similar error messages in official documents and it gave the following suggestions:

    When this exception is raised, the runtime executes all the finally blocks before ending the thread. Because the thread can do an unbounded computation in the finally blocks or call Thread.ResetAbort to cancel the abort, there is no guarantee that the thread will ever end. If you want to wait until the aborted thread has ended, you can call the Thread.Join method. Join is a blocking call that does not return until the thread actually stops executing.

    For more details , you could refer to this link :

    https://docs.microsoft.com/en-us/dotnet/api/system.threading.threadabortexception?view=netframework-4.8#remarks

    Best Regards,

    YongQing.

    Friday, September 6, 2019 9:48 AM
  • User1256154619 posted

    Our team was able to find a solution

    The error itself was very deceptive and irrelevant. The problem lied in the Authentication settings in the IIS

    Went to our website, chose Features View -> Authentication -> Forms Authentication

    Make sure that 'Requires SSL' is unchecked

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 12, 2019 2:48 PM
  • User753101303 posted

    IMO it's related even if not directly. Response.Redirect does work fine even on an https site. IMO it could be some flaw that causes a redirection to an http page. could it be that you have a configuration value somewhere that uses explictely http rather than https ?

    Thursday, September 12, 2019 3:10 PM