I am just playing arround with Profile Object in ASP.NET
2.0 and I just discovered an interesting thing. First of all here is my
web.config file which shows that I am using SQL SERVER 2000 to save my profile
object.
<!-- CONNECTION STRING-->
<connectionStrings>
<add name="ConnectionString" connectionString="Server=localhost
;Database=MyDatabase;Trusted_Connection=true"/>
</connectionStrings>
<system.web>
<anonymousIdentification enabled="true"/>
<profile defaultProvider="MyProfileProvider">
<providers>
<add name="MyProfileProvider" type="System.Web.Profile
.SqlProfileProvider" connectionStringName="ConnectionString"/>
</providers>
<properties>
<!-- COMPLEX PROPERTIES -->
<add name="User" allowAnonymous="false" type="User"
serializeAs="Binary"/>
I
have a simple class User which is mark
[Serializable]. So, I was checking that when the data in the aspnet_Profile
object is updated and I thought that the database trip was only made when
Profile.Save() is called. Well, I found out that everytime you read or assign to
the Profile object the trip to the database will be done. How do I know this?
Well, there is a field in the aspnet_Profile table LastUpdatedDate
which changes whenever you do the assignment or reading from the
Profile Object.
The
following line of code will make a trip to the database.
Profile.User.FirstName = "Jonathan";
Profile.User.LastName = "Donathy";
and so do this
one:
string firstName = Profile.User.FirstName;
string lastName = Profile.User.LastName;
Why are all
these trips to the database being made I thought properties in the Profile
Object are Cached?
powered by IMHO 1.3