Sign In

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: {#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!
Posted: 20-08-2010 | 1 comments | Filed under: Macro, API

Comments
Ryan Wheale
That sounds cool. I created a "Sign out via query string" web part to include on my master pages. Then, when the specified querystring exists (?signout=true), then the user is redirected to a specified page. If anyone is interested, email me at ryan [at] neteffectservices [dot] com
8/26/2010 3:20:25 AM
Leave comment



 Security code

About me

Jeroen Furst 
  • Facebook
  • LinkedIn
  • RSS
  • Twitter

Kentico DevNet

IBL-Software

Sponsored links

Interview with Kentico

You have an old version of Adobe's Flash Player. Get the latest Flash player.
Kentico blogs and websites
Martin Hejtmanek - Kentico CTO
Thomas Robbins - Kentico product evangelist
Petr Vozak - Kentico team leader
Brian McKeiver - BizStream
Johnny Bubriski - Wakefly, Inc.
Bryan Soltis - Bit-Wizards
Kentico Developer - Reed Business Information
Kentico Solutions - Data, Inc.

My trees

Latest Kentico Knowledge Base Articles

Kentico Developer Posters

Kentico CMS 5.5 Macro Reference