Answer failed.

I am having a problem calling response.redirect.

Error:

System.Threading.ThreadAbortException: thread terminated. in System.Threading.Thread.AbortInternal () in System.Threading.Thread.Abort (Object stateInfo) in System.Web.HttpResponse.End () at System.Web.HttpResponse.Redirect (String url, Boolean endResponse) in System. Web.HttpResponse.Redirect (String url) in Web.AdminUser.LoginHandler.OpenIdLogin () in C: \ Build \ 15 \ Digital \ main \ Sources \ Web \ Public \ LoginHandler.aspx.cs: line 113

Redirection occurs in a try - catch , and I cannot figure out how to do this correctly.

 try { if (Request.Form.HasKeys()) { Global.Logger.Info(string.Format("OpenIdLogin_Has_Keys")); string request = Request.Form.GetValues("token")[0].ToString(); Rpx rpx = new Rpx("123412341234", "https://login.youwebsite.com/"); var xml = rpx.AuthInfo(request).InnerXml; //lblx.Text = xml.ToString(); XElement xdoc = XElement.Parse(xml); if (xdoc.Element("email") != null) xdoc.Element("email").Value = ""; int userId = SaveMember(xdoc); if (userId > -1) { //add the user id to session for later Session["CurrentUserId"] = userId; Session["UserLoggedIn"] = true; } else { Session["UserLoggedIn"] = false; } articlePath = String.Format(articlePath, Section, Name); Response.Redirect(articlePath, false); } } catch (Exception e) { Global.Logger.Error(e); articlePath = String.Format(articlePath, Section, Name); Response.Redirect(articlePath, false); } 
+4
source share
3 answers

Try using this technique:

 Response.Redirect("...", false); HttpContext.Current.ApplicationInstance.CompleteRequest(); 

This should avoid a ThreadAbortException , but still execute the request.

+14
source

you can say Response.Redirect("home.aspx", false); and it will not stop the request.

but it will continue to be executed. so when using Response.Redirect("home.aspx", false);

If you pass false, you will not receive an error, but will not complete the request

correct me if I am wrong. But code like this

 public void Btn_Click() { if(count == 0) { Response.Redirect("OutOfStock.aspx", false); } Prospect.Save(-1, purchaceDate); } 

Even if count == 0

 Prospect.Save(-1, purchaceDate); 

will always work. And keep a new perspective when you can expect it to stop running

0
source

You should use below

 Response.Redirect("URL", false); 
0
source

Source: https://habr.com/ru/post/1379320/


All Articles