[Background]

There is a bug in BlogEngine.NET 2.5.

[Bug Description]

You cannot delete the subscribers from the newsletter widget.

[Repro Steps]

  1. Navigate to your BlogEngine.NET blog
  2. Log in as administrator
  3. Navigate to the Newsletter widget
  4. Click “edit” button on the right top of the widget
  5. Click “Delete” link on the edit panel
  6. Click “Save” button on the edit panel
  7. Repeat step 4 and observe the email list

[Actual Result]

The email address hadn’t been deleted from the email list.

[Expected Result]

The email address should be deleted from the email list successfully.

[Cause]

Code defect. The relative code file is ~\BlogEngine.NET\widgets\Newsletter\edit.ascx.cs.

If you investigate it you will find the doc variable always read the original email list from disk, even if you clicked the save button, in which case it should keep the new email list has some email addresses deleted.

[Solution]

You can download the revised code file from the below link and replace the original file with this one.

[File download]

edit.ascx.cs (5.47 kb)

 

[Remark to Solution]

The revised code file added 2 event handlers (Onunload(), OnLoad()) and modified 1 event handler (SaveEmails()). It uses the Session variable to store the modified doc (has some email addresses deleted).

 

[Updated code]

	// This event handler is append to the orignal file
        protected override void OnLoad(EventArgs e)
        {
            if (IsPostBack)
            {
                if (Session["docEmailList"] != null)
                {
                    doc = (XmlDocument)Session["docEmailList"];
                }
            }
        base.OnLoad(e);
    }

// This event handler is append to the orignal file
    protected override void OnUnload(EventArgs e)
    {
        Session["docEmailList"] = doc;

        base.OnUnload(e);
    }

    /// 
    /// Saves the emails.
    /// 
/// This event handler has already in the original file. I just append a statement (Session.Remove()) to it. 
    private void SaveEmails()
    {
        using (var ms = new MemoryStream())
        using (var fs = File.Open(fileName, FileMode.Create, FileAccess.Write))
        {
            doc.Save(ms);
            ms.WriteTo(fs);
        }
	
	// I append this statement:
        Session.Remove("docEmailList");
    }</pre>