9 YEARS AGO

API: Custom signout macro

Sometimes we get the request to create a menu item that works as a signout button. There are of course several ways to do this. For instance you could create a web part/widget and place it on the page which automatically signs the user out. In this post I will show you a different approach using a custom signout macro.

Basically the idea compared with the web part/widget is the same. You create a custom macro (App_Code\Global\CMS\CMSCustom.cs) using the following code:
case "signout":
   match = true;

   if (CMSContext.CurrentUser.IsAuthenticated()) {
      FormsAuthentication.SignOut();
      CMSContext.CurrentUser = null;
      HttpContext.Current.Response.Cache.SetNoStore();
   }

   break;
Next create a page and add the macro: {% ProcessCustomMacro("signout", "") %} via for example a static text web part and make sure the page is shown as menu item. Whenever the logged in user clicks on the menu item, he will be redirected to the page with the custom macro and thus be automatically signed out.

This is basically all you have to do to create a signout menu item. Now it's up to your imagination to use it in your websites!