Knowledge is power. We love to share it.

News related to Mono products, services and latest developments in our community.

khorvat

Support for ASP.NET profiles in MonoX

10/04/2010Categories: MonoX
We are proud to announce that MonoX now includes full support for ASP.NET profile infrastructure. Every MonoX administrator has an option to use the built-in profile which holds general user information, and to extend the built-in profile by using one of the following approaches:

- using the ASP.NET Profile infrastructure
- using the MonoX Profile templates

All configuration changes are immediatelly visible in the front end profile-related Web parts, making it easy to include unlimited number of custom fields to the user's profile without any programming and without the need to recompile the solution.
Before we start to explain how to use both approaches please read the following articles / manuals:

Using the ASP.NET Profile infrastructure

To extend the standard set of MonoX user profile properties you need to go to web.config and uncomment the profile section. You can take a look at the standard MonoX user profile here. It looks like this:

<profile enabled="true" defaultProvider="AspNetSqlProfileProvider">
    <providers>
      <remove name="AspNetSqlProfileProvider"/>
      <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer"
applicationName="MonoX" type="System.Web.Profile.SqlProfileProvider" /> </providers> <properties> <add name="GPSLocation" defaultValue="45.562141,18.676414"/> <add name="Children" /> <add name="RecentSearchList" type="System.Collections.Specialized.StringCollection" serializeAs="Xml" /> <add name="Hometown" type="String" serializeAs="String" /> <add name="IsModerator" type="bool" /> <group name="Bio"> <add name="Title" type="string" /> <add name="Description" type="String" /> </group> <group name="Publication"> <add name="Title" type="string" /> <add name="Description" type="String" /> <add name="Date" type="DateTime" /> </group> <add name="ClubJoinedYear" type="int" /> <add name="MoneyDonated" type="decimal" /> </properties> </profile>

When you uncomment the profile section you will notice that these demo properties set in web.config will appear above the "About me" field in the MonoX Profile page (which is in turn composed of Web parts that can be located in the /MonoX/ModuleGallery/ProfileModule folder). Note that only profile fields which have a value will be shown to a visitor. If you need to remove some fields from the standard MonoX profile you can do that programmatically by setting the HiddenFieldsString property of UserProfileModule or by setting the same property using the personalization service (please refer to the MonoX manual, Part 10, for more details on personalization): HiddenFieldsString="FirstName,LastName".

At this moment MonoX supports only simple .NET types. Here is the full list of supported types in version 3.2.1789.35:

object, string, bool, DateTime, int, Int16, Int32, Int64, char,
decimal, double, float, uint, long, ulong, short, ushort

MonoX introduces additional functionality on top of what ASP.NET profile infrastructure has to offer. For example, all ASP.NET profile fields automatically include the privacy level option:
Private - only the active user can see the field's data
Friends - user's friends can see the field's data
Public - every site visitor can see the field's data

Privacy roles can be extended in custom solutions and you can build a custom privacy layer on top of the existing functionality.

Extending the profile with MonoX Profile templates

If ASP.NET Profile doesn't suite your needs, if you want to have a more control over your code or you just want to implement some custom functionality, you can extend the MonoX profiles with profile templates.

MonoX profile provides you with three templates: MainContentTemplate (placed below the general profile fields), SideBarTemplate (placed under the avatar / gravatar) and FooterTemplate (placed at the bottom of the profile control). You can use these templates to add any custom controls and logic your project requires. Here are the few examples of MonoX Profile markup templates:

Main content tamplate

<MainContentTemplate>                                
    <div class="input-form">
        <dl class="profile-details">
            <dd>
                <asp:Label ID="labGPSLocation" AssociatedControlID="GPSLocation" runat="server"
Text="GPS Location" CssClass="label-bold"></asp:Label> <asp:Label ID="prevGPSLocation" runat="server"></asp:Label> <asp:TextBox runat="server" ID="GPSLocation" /> </dd> <dd> <asp:Label ID="labHometown" AssociatedControlID="Hometown" runat="server"
Text="Hometown" CssClass="label-bold"></asp:Label> <asp:Label ID="prevHometown" runat="server"></asp:Label> <asp:TextBox runat="server" ID="Hometown" /> </dd> </dl> </div> </MainContentTemplate>

Side-bar template

<SideBarTemplate>
    <div class="input-form">

        <dl class="profile-details">
            <dd>
                <asp:Label ID="labIsModerator" AssociatedControlID="IsModerator" runat="server"
Text="Is&nbsp;Moderator" CssClass="label-bold"></asp:Label> <asp:Label ID="prevIsModerator" runat="server"></asp:Label> <asp:CheckBox runat="server" ID="IsModerator" /> </dd> </dl> </div> </SideBarTemplate>

Footer template

<FooterTemplate>
    <div>

        <strong>Note: This is only a test</strong>                                    
        <p>
            Lorem ipsum dolor sit amet, ...
        </p>
    </div>
</FooterTemplate>


MonoX Profile tips:

- AutoDetectUser property of the User profile part (UserProfileModule.ascx) is used to automatically retrieve the ID of the profile owner - the default mechanism retrieves the ID of the currently active user. In many scenarios you will want to set the user ID explicitly: set the AutoDetectUser to false and than set the UserId to appropriate value.
- the custom control visibility is reflected by the property WorkingMode. It has two states, Edit and Preview, that can be checked at LoadComplete or PreRender to see what type of controls to show.

- to turn off the working mode switch for your end users, please set the profile part property ShowWorkingModeSwitch to false.

- if you want to hide the privacy manager from MonoX Profile pages/controls you need to set the Profile module property ShowPrivacyEditor to false.

- Default privacy level is public. If you want to change the default level you need to set the Profile module property DefaultPrivacyLevelId:

- UserProfileRepository.GetInstance().PrivacyLevelPublic.Id
- UserProfileRepository.GetInstance().PrivacyLevelFriends.Id
- UserProfileRepository.GetInstance().PrivacyLevelPrivate.Id

- If you want to modify or cancel the "My status" changes you can attach to the following events: MyStatusChanging and MyStatusChanged.

Summary

We recommend that you use basic, out-of-the-box MonoX profile page and parts for simple applications that do not need further customization.
Turn to ASP.NET profile support if you need the customization and flexibility it provides, but keep in mind that in internally uses XML and binary serialization to save the data.
MonoX profile templates are used in cases where you need the total control over the presentation of the profile fields.

Of course, you can choose to avoid the profile provider support altogether: this requires that you change the markup of the profile Web parts manually and introduce a dedicated DB table to hold all custom profile fields, with 1:1 relationship to the aspnet_users table. Although it givs you a total control of presentation and behavior aspects of all profile parts and pages, it is much more difficult to implement. The beauty of the "automated" techniques described in this article lies in the fact that no programming and compilation is required to produce completely customized profiles for your sites, so you can use it without much previous experience with both ASP.NET or MonoX.

Rated 4.17, 6 vote(s).