Implement a web service to delete orphaned user profiles

The following tutorial demonstrates creating a full implementation of a web service that takes care of removing orphaned UserProfile objects from Sitefinity CMS.

Define your DTOs and routes

The service will support deleting orphaned user profiles for a single user or for all users from a specified MembershipProvider. To do that you need to define two Request DTOs handling the delete by user ID and delete by providerName operations. Both Request DTO have the route specified. In this case the route is the same, but when used for deleting orphaned profiles for a single user it accepts a UserId parameter. The same route is used  for deleting all orphaned profiles for users under a particular membership provides, when a ProviderName parameter is passed.

You also need to define the matching Response DTOs:

Implement the service

In the service implementation you must implement two separate methods responsible for handling the business logic matching the respective Request DTO and route you already defined. The first method is responsible for deleting orphaned profiles for a single user, while the second one takes care of deleting orphaned profiles for all users in a specified membership provider.

Implement the plugin and register the service

In the plugin you must implement the IPlugin interface and inside the Register method specify the type of the service you want to register:

Once you have all the components ready you must register the plugin in your Global.asax:

As a result, you can consume your new web service by calling it:

 

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?