YAFLogo

tommy382
  • tommy382
  • 100% (Exalted)
  • YAF Commander Topic Starter
2011-03-13T04:34:36Z
In version 1.9.5.5RTW, when a user email another user via the forum, the email got sent properly and there is no error message reported. However, the error log will have something like below. Any idea why?


System.Threading.ThreadAbortException: Thread was being aborted.
   at System.Threading.Thread.AbortInternal()
   at System.Threading.Thread.Abort(Object stateInfo)
   at System.Web.HttpResponse.End()
   at YAF.Pages.im_email.Send_Click(Object sender, EventArgs e)
Sponsor
tommy382
  • tommy382
  • 100% (Exalted)
  • YAF Commander Topic Starter
2011-03-13T05:06:20Z
The root cause of this is explained here .

I applied the work-around suggested on that page and it works great. The code changes are below.

im_email.ascx.cs:


    protected void Send_Click([NotNull] object sender, [NotNull] EventArgs e)
    {
      try
      {
        // get "to" user...
        MembershipUser toUser = UserMembershipHelper.GetMembershipUserById(this.UserID);

        // send it...
        this.Get<ISendMail>().Send(
          new MailAddress(this.PageContext.User.Email, this.PageContext.User.UserName), 
          new MailAddress(toUser.Email.Trim(), toUser.UserName.Trim()), 
          this.Subject.Text.Trim(), 
          this.Body.Text.Trim());

        // redirect to profile page...
        //Tommy: use overloaded function to avoid ThreadAbortException.
        YafBuildLink.Redirect(ForumPages.profile, false, "u={0}", this.UserID);
      }
...

YafBuildLink.cs:


    /// <summary>
    /// Redirects to the given page with parameters.
    /// </summary>
    /// <param name="page">
    /// Page to which to redirect response.
    /// </param>
    /// <param name="format">
    /// Format of parameters.
    /// </param>
    /// <param name="args">
    /// Array of page parameters.
    /// </param>
    public static void Redirect(ForumPages page, string format, params object[] args)
    {
      Redirect(page, true, format, args);
    }

    /// <summary>
    /// Redirects to the given page with parameters.
    /// </summary>
    /// <param name="page">
    /// Page to which to redirect response.
    /// </param>
    /// <param name="endResponse">True to end the Response, false otherwise.</param>
    /// <param name="format">
    /// Format of parameters.
    /// </param>
    /// <param name="args">
    /// Array of page parameters.
    /// </param>
    public static void Redirect(ForumPages page, bool endResponse, string format, params object[] args)
    {
      HttpContext.Current.Response.Redirect(GetLinkNotEscaped(page, format, args), endResponse);
    }
tommy382
  • tommy382
  • 100% (Exalted)
  • YAF Commander Topic Starter
2011-03-16T09:49:55Z
Can someone commit this code? I want to pickup this change automatically in the next release without manually fixing im_email.ascx.cs.
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 3.0.0 RC 3
2011-03-16T10:11:05Z
Originally Posted by: tommy382 

Can someone commit this code? I want to pickup this change automatically in the next release without manually fixing im_email.ascx.cs.

Added in SVN #4783


UserPostedImage