Sitecore user profile custom properties are case sensitive

Search for a command to run...

No comments yet. Be the first to comment.
Polly is great library for easily configuring different kinds of policies around code execution, be it retry, circuit breaker, caching or lots of other things. It's probably most often used around HTTP requests. If you haven't heard about it you defi...

This is part 2 of my series on unit testing in .NET (C#) and will be about my conventions regarding naming unit tests, how to structure them and which parts to test. And lastly I will help you increase readability of assertions and potential error me...

I feel like unit testing is very important and very beneficial in a lot of ways. It helps with not breaking existing functionality and thereby also making you more confident in changing code without fear of breaking important stuff. Often it also mak...

I've been working with Swagger through NSwag a lot recently and also needed to get it to work when hidden behind a reverse proxy - i.e. another service forwarding a request to the service exposing the Swagger UI. Some of the issues I've had along the...

The other day I was writing a unit test to verify what was supposed to happen when a Task would throw an exception when awaited. It wasn't as straight forward as I first assumed, but I quickly found this Stack Overflow post that helped me: https://st...

I recenty ran into some unexpected behavior from Sitecore when working with custom properties on user profiles. I were trying to get the value of a custom property on a user profile, but the returned value ended up being null even though I was sure the property was there and that it had a value.
// This is null even though the user profile has a custom property named "Country"
var country = Sitecore.Context.User.Profile.GetCustomProperty("country");
// Another way to get property values (not just custom properties)
// but the result is the same as above
var country = Sitecore.Context.User.Profile["country"];
It turns out that the property names are case sensitive – and the custom property on the user profile was Country with a capital ‘C’!
Most of your are probably used to Sitecore not caring about casing when accessing item fields etc. at least I am.
// Both of these will return the raw value of the "Title" field
var title1 = item["title"];
var title2 = item["Title"];
// Both of these will return the "Title" field
var field1 = item.Fields["title"];
var field2 = item.Fields["Title"];
But that is not how the GetCustomProperty method works and the reason is how the custom properties are stored internally in the UserProfile class. The class uses a Dictionary<string, string> to store the custom properties and the key is then of course case sensitive.
So beware when accessing custom properties on user profiles and make sure you are using the same casing as the field name.
Don’t know how to add custom properties to user profiles? Have a look at this blog post: http://www.ipointsystems.com/blog/2013/may/adding-custom-fields-to-sitecore-user-part-1