locked
identityHelper throws 'System.Threading.ThreadAbortException' in mscorlib.dll RRS feed

  • Question

  • User-2139767974 posted

    My application was working fine but after few minor changes i can't login .. its not even showing any message .. after bit of debugging i found that

    IdentityHelper.RedirectToReturnUrl(url, Response) throws  Exception thrown: 'System.Threading.ThreadAbortException' in mscorlib.dll

    any idea how to solve this ..

    Thursday, August 3, 2017 8:14 AM

Answers

  • User1771544211 posted

    Hi mubashirhan,

    its a method generated by vs template on its own..  i tried both  options but nothing worked..

    Which code do you modify?

    The source code of the IdentityHelper.RedirectToReturnUrl() is located at Identity.Model.:

            public static void RedirectToReturnUrl(string returnUrl, HttpResponse response)
            {
                if (!String.IsNullOrEmpty(returnUrl) && IsLocalUrl(returnUrl))
                {
                    response.Redirect(returnUrl);
                }
                else
                {
                    response.Redirect("~/");
                }
            }

    Please try modify the above code to the following.

            public static void RedirectToReturnUrl(string returnUrl, HttpResponse response)
            {
                if (!String.IsNullOrEmpty(returnUrl) && IsLocalUrl(returnUrl))
                {
                    response.Redirect(returnUrl,false);
                }
                else
                {
                    response.Redirect("~/",false);
                }
            }

    Then rebuild the solution and try  again.

    Best Regards,

    Jean

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 8, 2017 5:39 AM

All replies

  • User753101303 posted

    Hi,

    This is how redirect ask to stop processing the request. A quick fix is to avoid including Redirect calls inside your try block.

    Or pass false for the endResponse argument and then call https://msdn.microsoft.com/en-us/library/system.web.httpapplication.completerequest(v=vs.110).aspx to terminate the request (maybe as an extension method).

    Thursday, August 3, 2017 1:05 PM
  • User-2139767974 posted

    i am not using try catch block..

    tried endcomplete .. that didnt worked either..

    some times it does login .. but not always..

    i can send u the whole project code if u wana..

    Thursday, August 3, 2017 4:30 PM
  • User1771544211 posted

    Hi mubashirkhan,

    IdentityHelper.RedirectToReturnUrl(url, Response) throws  Exception thrown: 'System.Threading.ThreadAbortException' in mscorlib.dll

    Is the IdentityHelper.RedirectToReturnUrl(url, Response) a custom method that written by you? Could you please share the code of this method here?

    Best Regards,

    Jean

    Friday, August 4, 2017 5:31 AM
  • User753101303 posted

    How do you see that it happens ? Wth VS configured to show absolutely all exceptions? If yes, this is likely not what actually causes your original issue.

    Friday, August 4, 2017 5:59 AM
  • User-2139767974 posted

    Patrice .. i guess you are right.. i see this error in the vs output window.. it always throws this exception whenever login happens..

    but my problem is most of the times the login succeeds and it works as expected.. but when i try to login from another browser (sometimes same browser) it doesn't work..

    it doesnt show any invalid login message or something like that .. it simply posts back to login page.. 

    Friday, August 4, 2017 8:01 AM
  • User-2139767974 posted

    Jean its a method generated by vs template on its own..  i tried both  options but nothing worked..

    1- Response.Redirect("Default.aspx",true);
    
    2- Response.Redirect("Default.aspx",false);
    Context.ApplicationInstance.CompleteRequest();
    Friday, August 4, 2017 8:06 AM
  • User1771544211 posted

    Hi muhashirkan,

    Which VS template do you use?

    IdentityHelper.RedirectToReturnUrl(url, Response)

    Could you please share more code that close to above code here?

    Best Regards,

    Jean

    Monday, August 7, 2017 6:25 AM
  • User-2139767974 posted

    Hi jean..

    i am using  web forms (4.5.2) template..  here is the code that might help

    protected void LogIn(object sender, EventArgs e)
           {
               if (IsValid)
               {
     
                   // Validate the user password
                   var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
                   var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();
     
                   // This doen't count login failures towards account lockout
                   // To enable password failures to trigger lockout, change to shouldLockout: true
                   var result = signinManager.PasswordSignIn(UserName.Text, Password.Text, RememberMe.Checked, false);
     
     
                   switch (result)
                   {
                       case SignInStatus.Success:
                           IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
     
                           break;
                       case SignInStatus.LockedOut:
                           // Response.Redirect("/Account/Lockout");
                           break;
                       case SignInStatus.RequiresVerification:
                           Response.Redirect(
                               string.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                   Request.QueryString["ReturnUrl"],
                                   RememberMe.Checked),
                               true);
                           break;
                       case SignInStatus.Failure:
                       default:
                           FailureText.Text = "Invalid login attempt";
                           ErrorMessage.Visible = true;
                           break;
                   }
               }
           }
    Monday, August 7, 2017 5:29 PM
  • User1771544211 posted

    Hi mubashirhan,

    its a method generated by vs template on its own..  i tried both  options but nothing worked..

    Which code do you modify?

    The source code of the IdentityHelper.RedirectToReturnUrl() is located at Identity.Model.:

            public static void RedirectToReturnUrl(string returnUrl, HttpResponse response)
            {
                if (!String.IsNullOrEmpty(returnUrl) && IsLocalUrl(returnUrl))
                {
                    response.Redirect(returnUrl);
                }
                else
                {
                    response.Redirect("~/");
                }
            }

    Please try modify the above code to the following.

            public static void RedirectToReturnUrl(string returnUrl, HttpResponse response)
            {
                if (!String.IsNullOrEmpty(returnUrl) && IsLocalUrl(returnUrl))
                {
                    response.Redirect(returnUrl,false);
                }
                else
                {
                    response.Redirect("~/",false);
                }
            }

    Then rebuild the solution and try  again.

    Best Regards,

    Jean

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 8, 2017 5:39 AM
  • User-2139767974 posted

    jean

    i didnt modified any login code..  i think it all started when i tried to use session variables (HttpContext.Current.Session["ClgCode"].ToString(); ) on other pages..

    i guess ur solution is working for now.. will get back if the problem repeats ..

    Thankx...

    Tuesday, August 8, 2017 1:05 PM