Try our conversational search powered by Generative AI!

Creating a custom attribute for IUser


I'd like to extend the IUser with a list of companies and the user's function in the company. What's the easiest way to create such attribute?
I've already seen the blogs about creating a custom module (, but that seems like overkill for this case. I tried to create a custom attribute using this blog, but I get an error saying that the input string was not in a correct format when I try to save the details in 'EPiServer.Common.Data.AttributeFactory.UpdateEntityAttributes'.

The idea is to be able to enter a company name and, per company, select a function from a dropdownlist.

Jun 01, 2011 18:25

Sounds like you could do with just storing strings? You can store a string attribute as a single value (SetAttributeValue/GetAttributeValue) or multiple values (SetAttributeValues/GetAttributeValues) that are stored with the same key. Just store your company-funcion pair as for example a comma separated string and store multiple such pair using SetAttributeValues. Or you could store an xml document as a single string if you need more flexibility (but querying would get more complicated an expensive).

Jun 01, 2011 23:48

Sounds good, but do you have an example of how to implement this? Do I need to inherit a specific class?

When I change the attribute type to inherit 'StringAttributeType', I have no option to specify the edit-control. The admin-pages only shows a single textbox instead of a textbox and a dropdownlist.

Edited, Jun 06, 2011 10:09

Ah, I didn't realize you also wanted to edit the attribute from admin mode. I thought you only wanted to set it from code (and in that case you don't need a class, just set the string value). I don't know if there is any built in support to extend the admin interface. But perhaps you can figure out which control is displaying the attribute editing, create your own modified clone and use the Virtual path mapping provider to replace the control with your own.

Jun 07, 2011 9:59

Editting in the admin isn't necessary, but using it in a query is. I've just tested setting the attribute in code, which works fine. But using the value (part of it since it's a comma-separated value) in a query isn't that easy.


I tried again using the example mentioned before. My code is exactly the same as the one from the example, but for some reason the method AddEntityInstance is never called. Can anyone explain this? Should this method be called as soon as I create another attribute (in the admin or in code) ?

Edited, Jun 07, 2011 11:49

Ok, finally I managed to get the attribute working. I had to much code from the example, where the attribute was also an entity. In my case, that wasn't necessary.

But how can I use this attribute in a query? My custom class consists of two strings, but a stringcriterion isn't working. Should I create a custom criterion-class? I can't find any examples on this.

Jun 07, 2011 17:52

I've just done like this:

Works fine using attributes on IUser

Jun 10, 2011 15:27

Creating properties for the attributes wasn't my problem, but using the attributes in a query is. I think it shouldn't be that difficult, but it doesn't seem to work.

Jun 14, 2011 16:44
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.