I have been configuring an application, and something which I have never noticed struck me, and its only small but it gave me ideas and some critisms. If you use the Sql Profile Provider, then you are no doubt defining properties inside the web.config file for example:
<profile defaultProvider="ProfileProvider">
<providers>
<add name="ProfileProvider" connectionStringName="EmailSqlServer" applicationName="EmailApplicationServer" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
<properties>
<add allowAnonymous="false" name="ApplicationID" type="int"/>
<add allowAnonymous="false" name="SmtpServer" type="string"/>
<add allowAnonymous="false" name="Port" type="int"/>
<add allowAnonymous="false" name="EmailUsername" type="string"/>
<add allowAnonymous="false" name="Password" type="string" serializeAs="Binary"/>
</properties>
</profile>
Once this is done and you save this information against a user, it is then stored in the database. It is this part which surprised me, in that I was simply unaware of its methodology. To begin with you can serialize your properties in the following ways:
- Binary
- Xml
- String
- ProviderSpecific
Next the dbo.aspnet_Profile table in SQL has the following columns:
- UserID
- PropertyNames
- PropertyValuesString
- PropertyValuesBinary
- LastUpdatedDate
So if we look at at PropertyNames in the database which corresponds to the above Web.Config section we see this:
SmtpServer:S:0:18:Port:S:18:2:Password:B:0:48:ApplicationID:S:20:1:EmailUsername:S:21:15:
Brilliant, so simple yet perfect. Here we have the following sections, take SmtpServer for instance:
Property Name : SmtpServer
Property Type : string (S) <-- Or this could be the Serialize As Type
Property Start Index : 0
Property String Length : 18
This now corresponds to the next column in the database table, which is PropertyValuesString, which again for the above Web.Config section contains the following:
pop.abcdefgh.co.uk257abcdefghij-abcd
Just one long string, which given the first set of information, we can navigate very easily. We have the Start Index of the string and the length.
Cheers,
Andrew