mojoPortal content management system includes a flexible User Profile System which allows simple customization of the User Profile. A default installation has a specific set of User Profile Properties, but you can remove Properties that you don't need or add Properties that you do need to make the User Profile more suitable for your purposes.

Adding and Removing User Profile Properties

To add or remove User Profile Properties, you only need to create a new configuration file, using the mojoProfile.config file at the root of the site as your starting point. It is a simple text file and can be edited with any text editor like Notepad. Once you have created your new file, add/change this setting in your user.config to point to your custom file: <add key="mojoProfileConfigFileName" value="CustomProfile.config" />.

Custom Configuration for Multi-Tenant Installations

For a multi-tenant installation you can use a different profile configuration file for each site by adding a config setting like this: <add key="mojoProfileConfigFileName-2" value="site2profile.config" />.

The value can be named as you like, but for it to find your setting the key must be in the shown format where "2" in the example is the site id for site 2 and you can add additional ones for site 3, 4, etc.

Two of the properties in the default mojoProfile.config are Gender and Web Site Url. These are good examples that show most of the features of the User Profile system, so we will look at them in detail. First, here is what the properties look like in the mojoProfile.config file.

<add name="Gender"
  type="System.String"
  allowMarkup="false"
  resourceFile="ProfileResource"
  labelResourceKey="GenderLabel"
  lazyLoad="false"
  requiredForRegistration="false"
  showOnRegistration="false"
  allowAnonymous="false"
  visibleToAnonymous="false"
  visibleToAuthenticated="true"
  visibleToUser="true"
  editableByUser="true"
  regexValidationExpression=""
  regexValidationErrorResourceKey=""
  onlyAvailableForRoles=""
  onlyVisibleForRoles=""
  defaultValue=""
  includeHelpLink="true"
  >
  <OptionList>
      <Option value="" TextResourceKey="GenderUnselectedLabel"></Option>
      <Option value="M" TextResourceKey="GenderMaleLabel"></Option>
      <Option value="F" TextResourceKey="GenderFemaleLabel"></Option>
  </OptionList>
</add>
name (mandatory)
must be unique for each property in the mojoProfile.config file, it is the name of the property. Note that all properties are case sensitive.
type (optional, defaults to System.String)
this setting is used to determine how to render the property.
System.Boolean
renders as a Checkbox for editing the property and in read only mode as an image from the skin folder, true.png or false.png.
System.DateTime
renders in edit mode as a DatePicker.
Others
For all other types we render a TextBox for editing the property, unless the property has an OptionList configured with at least one Option. In that case we render a DropDownList for editing.
includeTimeForDate(optional, defaults to false)
only used when type is set to System.DateTime. If true the DatePicker will also show time.
resourceFile (optional, defaults to ProfileResource)
this is not shown above, ProfileResource corresponds to App_GlobalResources/ProfileResource.resx but you can override it and get resources from a different file. When specifying a resourceFile use the name of a resource file that exists in App_GlobalResources, but leave off the file extension.
labelResourceKey (optional, but no label will be shown if blank)
this value is used for the label associated with the property. It is localizable by putting a resource key here that exists in the App_GlobalResources/ProfileResource.resx file. If no resource is found then this property is used for the label directly so it is not required to edit the Resource files but it is recommended.
lazyLoad (optional, defaults to false)
in most cases you should leave this set to false. When set to true, the property will be loaded from the database on demand rather than as a group with the other profile properties. This should only be true for seldom used or particularly expensive to retrieve properties.
showOnRegistration (optional, defaults to false)
if set to true the property will appear on the registration page but the user will not be required to enter a value.
requiredForRegistration (optional, defaults to false)
if set to true, the property will appear on the registration page when a user registers on the site and will require a value.
allowAnonymous (optional, defaults to true)
this setting is for future use, if we need to capture property values from anonymous users. It is not currently used.
visibleToAnonymous (optional, defaults to false)
if the Web.config setting "AllowAnonymousUsersToViewMemberList" is set to true, then anonymous users can see the Member List for the site. On the Member List page there is a "View Profile" link to view the profile of other Members. Setting "visibleToAnonymous" to false means that only authenticated users can see this property on another member's profile view.
visibleToAuthenticated (optional, defaults to true)
applies to the Profile View page. Set this to false for properties that should be visible only to the user or site admins.
visibleToUser (optional, defaults to true)
you may want to have properties that only site administrators can see. Set this setting to false and only site administrators will be able to see the property.
editableByUser (optional, defaults to true)
if you don't want the user to be able to edit this property, set this to false. A user also cannot edit a property if it is not visible.
regexValidationExpression(optional)
enter a RegularExpression here to enforce validation on your property so that only valid values can be entered. See the WebSiteUrl property example below, it has a Regular Expression that enforces that the WebSiteUrl property starts with either http:// or https://. For more on Regular Expressions, you can find a lot of examples for common validation scenarios on this site: http://www.regxlib.com/
If left blank no validation will occur.
regexValidationErrorResourceKey(optional, but should be specified if using regexValidationExpression)
when a user enters a value that fails to pass your validation expression, it is a good idea to show a message giving some idea of the expected value. You can enter this message here or add it to the App_GlobalResources/ProfileResource.resx file and just put the key here.
onlyAvailableForRoles (optional, default value is an empty string which means its visible to all roles)
sometimes you may want a property to be only available for certain roles. For example if you wanted a property to only be available to members of the Admins and Content Administrators roles, you would put "Admins;Content Administrators", separating each role name with a semicolon.
onlyVisibleForRoles (optional, default value is an empty string which means its visible to all roles)
sometimes you may want a property to be only visible for certain roles. For example if you wanted a property to only be available to members of the Admins and Content Administrators roles, you would put "Admins;Content Administrators", separating each role name with a semicolon. NOTE: the onlyVisibleForRoles setting takes precedence over all other "Visible" settings.
defaultValue (optional)
can be used to specify a default for the property that will be used when new users are created.
includeHelpLink(optional, defaults to false)
if set to true a  help link will be displayed next to this property on the UserProfile.aspx or Admins/ManageUsers.aspx page. Members of the Admins or Content Administrators role will then be able to edit the help for this property.
OptionList (optional)
allows you to configure a list of possible options that will appear as a dropdown list.
<add name="WebSiteUrl"
  type="System.String"
  allowMarkup="false"
  resourceFile="ProfileResource"
  labelResourceKey="WebSiteUrlLabel"
  lazyLoad="false"
  requiredForRegistration="false"
  allowAnonymous="true"
  visibleToAnonymous="true"
  visibleToAuthenticated="true"
  visibleToUser="true"
  editableByUser="true"
  regexValidationExpression="(((http(s?))\://){1}\S+)"
  regexValidationErrorResourceKey="WebSiteUrlRegexWarning"
  maxLength="100"
  cssClass="widetextbox"
  onlyAvailableForRoles=""
  onlyVisibleForRoles=""
  includeHelpLink="true"
/>

Note that the WebSiteUrl property renders on the ProfileView.aspx page as a hyperlink to the user's web site. If you have a custom property with "Url" in the name the property will be rendered as a hyperlink. It is up to you to use a regular expression to make sure the value entered by the user in edit mode is appropriate.

For properties that render in edit mode as a TextBox, you can also set a maxLength which determines the maximum number of characters that will be allowed for the property. If maxLength is 0 then there is no limit on the length.

The columns property determines the width of the TextBox. You can also specify a rows property, if rows > 1, then the TextBox will be configured with multiple lines (a textarea in html).

Author Biography Profile Property

As of mojoPortal version 2.3.9.4 we've added a new default profile property for Author Biography. The purpose of this property is for use with content authors so that a brief author biography can be shown at the bottom of an HTML Content instance or a Blog post.

The property is configured in mojoProfile.config file in the root as follows:

<add name="AuthorBio"
  type="System.String"
  allowMarkup="true"
  resourceFile="ProfileResource"
  labelResourceKey="AuthorBio"
  lazyLoad="false"
  requiredForRegistration="false"
  allowAnonymous="true"
  visibleToAnonymous="false"
  visibleToAuthenticated="false"
  visibleToUser="true"
  editableByUser="true"
  regexValidationExpression=""
  regexValidationErrorResourceKey=""
  maxLength="2000"
  rows="5"
  cssClass="widetextbox"
  onlyAvailableForRoles="Admins;Content Administrators;Content Authors;Content Publishers;"
  onlyVisibleForRoles="Admins;Content Administrators;Content Authors;Content Publishers;"
  includeHelpLink="true"
/>

With the default settings this property only shows up in the user profile for users who are members of the Administrators, Content Administrators, Content Authors, or Content Publishers roles.

If you want to customize these roles you'll need to configure the use of a custom profile configuration file instead of using the default mojoProfile.config file. That way any modifications you make will not be lost on the next upgrade of mojoPortal. See the article User Profile Configuration for more details.

The HTML Content Feature and the Blog feature have settings to enable showing the Author Bio. However, it will only be shown if the Author Bio is actually populated from the author's user profile.

Creating Properties with Code

Note that the configuration file is for configuring user properties that show up in the user profile page. It is also possible to create and retrieve arbitrary properties for authenticated users that are never shown on the user profile pages.

if(Request.IsAuthenticated)
{
  SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
  siteUser.SetProperty(propertyName, propertyValue);
  string somePropertyValue = siteUser.GetCustomPropertyAsString(propertyName);
}

Restricted Property Names

Some names will clash with core user properties.  Custom profile properties with these names will be ignored.

  • UserID
  • UserGuid
  • Name
  • LoginName
  • Email
  • Password
  • PasswordQuestion
  • PasswordAnswer

Custom Property Usage by mojoPortal

There are 4 pages in a mojoPortal site that are populated from the settings in mojoProfile.config

  • Admin/ManageUsers.aspx is used by Site Administrators to manage user settings. All User Profile Properties are editable by members of the Admins role.
  • Secure/UserProfile.aspx is used by the user to edit his/her own profile properties.
  • ProfileView.aspx is a read only page for viewing the profiles of other users
  • Secure/Register.aspx is used to Register a User Account in a site and User Profile Properties can be configured so that they are required for Registration.