FileSharedPersonalizationProvider
Looking at the provider model of ASP.NET 2.0, I thought it would be nice to write my own PersonalizationProvider. Just to see how it all works.
The WebPart framework in ASP.NET 2.0 uses a PersonalizationProvider to read and store it's WebPart data (i.e. information about the webparts on a page). WebParts can be added for SharedScope (for all users) and UserScope (per user). Because I'm only interested in the SharedScope WebParts, I thought it would be a good idea to store this SharedScope information somewhere on the filesystem, and not in a database (like the default PersonalizationProviders do).
Even better: why not store the SharedScope pagesettings inside the .aspx file itself, as a Base64 encoded string in the 'Description' attribute of the <%@ page %> directive! An .aspx page containing SharedScope PageSettings would then look something like this:
By reading the SharedScope PageSettings from the .aspx page itself, no database interaction is needed! Also, the PageSettings can be put in Cache, with a dependancy to the .aspx file itself. So by writing new PageSettings to the .aspx page, the Cached PageSettings are invalidated automatically.
To use the FileSharedPersonalizationProvider, configure it in the web.config like this:
And here's the source code for the FileSharedPersonalizationProvider. Note that my FileSharedPersonalizationProvider:
- doesn't load or save UserScope pagesettings,
- throws errors when the impersonated user has no rights to write the .aspx page
- doesn't use a lock for reading and writing files