I returned to serious DotNetNuke development this year after a gap of more than a couple of years probably. And I must say, I did not see much changes as far as the public API of DotNetNuke is concerned. Yes, there have been good UI changes, some new capabilities but the underlying framework feels the same (this was in stark comparison to my last year’s experience with migration from Drupal 6 to Drupal 7, where the entire Drupal API was overhauled, and here in DotNetNuke, the framework had notched up by 2 major versions).

Anyways, a very common requirement clients demand when we deploy DotNetNuke for them is to customize DNN’s user handling capabilities specific for them (e.g. in iMLM product we developed for Multi-Level Marketing companies, the requirement was to bypass DNN’s user handling completely and create custom UI allowing managing users as “Distributors”).

So this time, I was working on ICSI’s student management website, where we were completely re-coding the site using DotNetNuke 6. And the client was not at all interested in DNN’s user concept, they were only concerned about a “Student” registered on their site. And so, we were creating custom modules for them which would allow them to manage Students.

One aspect of these module was to delete Students from our module, which I thought should have been pretty easy, as we had done this multiple times before (removing a DNN user programatically), simply invoke the following:


UserController.DeleteUser(ref u, false, false);

So, I created a test Student (aka a user), played with the profile and finally deleted it using our custom module. So far so good.
Then I went ahead and tried to create another user with the same username as the one I had just deleted, guess what, I got a “a user with the same Username already exists” error.

Caught unawares, I looked into the database and the user I had deleted was there in the tables. What the heck I thought, I just deleted this user. I was aware that DNN had introduced a soft-delete feature for users somewhere in between but I was using the API and not the UI, so the “DeleteUser” function should do what it is supposed to do, remove that user permanently.

As this was not happening, I started poking around in the UserController API, and found a new public method, the “RemoveUser” method.

So I updated my code and added a call to “RemoveUser” method after the call to “DeleteUser” method, and the next time I deleted a user using our modules, it was gone for good from the database too.

To cut the long story short, here are 2 easy lines to remove a DNN user permanently in your code:

UserController.DeleteUser(ref u, false, false);

Here “u” is a reference to the UserInfo object you are trying to delete.