Sitecore – Extra Fields on Membership

Hello! Now I want to discuss about membership in Sitecore. I won’t tell in detail. I will focus in how could these membership can be used simply for some features.

In my application, there’s a membership that using extranet\ role. So I use membership class. Membership in Sitecore is basically the same with .NET Membership class. Well, they inherit .NET. So if you’ve learned and know about .NET membership class, you can make log in, log out, register, forgot password, and edit profile page easily. And also, if you want such tutorial, I won’t giving it because if you google it, there are blogs that have given step-by-step guide already. Just follow it. 🙂

Sitecore allows us to create an extra field. What is that? I don’t know exactly, but you can add a field on your user object and it will be stored in database. Let’s not discuss about how Sitecore manage it. These fields can be accessed like a dictionary (array of object with string as the key). It makes the custom fields are easier to manage. You just have to define the key then use it everywhere.

You also knew that developers can create a custom membership for sitecore. But as I look deeper, it is confusing if you only have a short time to develop a complex membership (confusing if you are new to Sitecore of course). So let’s just use this custom field where you can add values just by adding fields needed. For example in my app, I want the user have phone number and address. Should I create a custom membership and let even the administrative users have phone number and address? I don’t think so. I could just add two fields every time an extranet\ user register their account. I can edit those two fields anytime I want to.

For now I can’t give you the code example because I am not at my office and I left the code there. I promise will edit this tomorrow.

To create those extra field, you can modify the code below.

Sitecore.Security.Accounts.User user = authHelper.GetActiveUser();
user.Profile.SetCustomProperty("key", "value");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s