Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 as the line 116 points just to a bracket. Can somebody please help me with code? Thank you all in advance


At this point I am at a loss and run out of ideas, especially considering the very same code with the same configurations works in other regions/boxes, such as prod region, test region, or dev region

Down below I paste an entire code with attached lines

Thank you in advance for your all the help

I did already post this question in the StackOverflow and Forums.asp.net and it was suggested to:
Use Context.ApplicationInstance.CompleteRequest(); after the Response.redirect - didn't work
Use Server.Execute or use Server.Transfer instead of the Response.recirect. That allowed to get to view Public.aspx page (page that is being redirected to after the successfull login) but the authentication itself didn't happen. Thus, any other link wouldn't redirect to its corresponding page but would instead bring the user back to Login.aspx with the correcponding ReturnURL query string parameter.
I tried to use ThreadAbortException with (and without) Thread.ResetAbort() inside - didn't work
At this point I am at a loss and run out of ideas, especially considering the very same code with the same configurations works in other regions/boxes, such as prod region, test region, or dev region

Down below I paste an entire code with attached lines

Thank you in advance for your all the help

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 }


What I have tried:

I did already post this question in the StackOverflow and Forums.asp.net and it was suggested to 

    Use Context.ApplicationInstance.CompleteRequest(); after the Response.redirect - didn't work
    
    Use Server.Execute or use Server.Transfer instead of the Response.recirect. That allowed to get to view Public.aspx page (page that is being redirected to after the successfull login) but the authentication itself didn't happen. Thus, any other link wouldn't redirect to its corresponding page but would instead bring the user back to Login.aspx with the correcponding ReturnURL query string parameter.
    
    I tried to use ThreadAbortException with (and without) Thread.ResetAbort() inside - didn't work
Posted
Updated 10-Sep-19 9:04am
v3
Comments
[no name] 10-Sep-19 14:58pm    
You said: it's a "different environment" (problem).

So, find the difference and / or make it the same. Sometimes the cause of death is unknown.

It may surprise you.. but this is exactly what is happening; as the redirect leaves the current code block before it is completed.
And I see you have already tried playing around with HttpContext.Current.ApplicationInstance.CompleteRequest(); to get around this; bet you tried changing the false to true on the Redirect method's overload.

I basically gave up on fixing all of these; and instead, implemented multiple layers of catch statements- effectively ignoring the Thread Abort
C#
try {
  // code 
}
catch (ThreadAbortException) {
  // IGNORE: this is normal behavior for Redirect method
}
catch (Exception ex) {
  // error logging routine
}
As I am now working with MVC based sites, I am wrapping the Redirect within an extension to the standard View object and don't worry about the WebForm stuff anymore

just a note, having the line numbers included in your code makes it a real pain in the butt for others to read the code online or work with in an editor
 
Share this answer
 
Comments
BillWoodruff 11-Sep-19 7:34am    
+5
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


https://i.stack.imgur.com/tvIDj.png[^]
 
Share this answer
 
Comments
Richard Deeming 13-Sep-19 12:17pm    
An extremely bad idea. Your authentication ticket will now be sent with insecure HTTP requests, which means it could be stolen by anyone who can spy on traffic between your computer and the server.

Your site should only ever be accessed over HTTPS, and all cookies should be set to "secure" to ensure they're never sent over an insecure connection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900