Asp.Net API Hall of Shame: PersonalizationProvider

by Matt 4. September 2006 18:16

This is a post I've wanted to write for a while. And I wrote it last night, and got it all wrong. Long winded, rambling and not really saying what I wanted to say. So I've got rid of that one, and let's try again.

SingleUserBlog uses WebParts on it's master page. This is a brilliantly simple idea that allows every single page on the site to share a common, personalisable layout.

The only problem is that WebParts don't support this.

Or more accurately, the PersonalizationProvider doesn't support it.

Allow me to introduce you to a big offender in the API hall of shame - PersonalizationProvider. This is the base class for the provider model used in the persistence of web parts. It saves layout and content changes made to a specific page, for a specific user (if logged on).

It's first offence is a poor separation of responsibility. Considering that the WebPartManager is in charge of, well, managing web parts, you'd be forgiven in expecting it to tell the personalisation provider what data to persist, what page it was for, and who the user was. Similarly, to get the data, it would ask the personalisation provider for what it had saved against a specific page with the current user. Master pages would be dead easy, then. Simply have the WebPartManager pass a global key for the page. Job done.

Since we're talking Hall of Shame here, you know that isn't what happens. The PersonalizationProvider is responsible not only for persisting the data (and reading it back in) but also for deciding what the unique keys are! (And it uses internal System.Web methods to do that, too.) Reading data back into the WebPartManager now occurs via telepathy - the PersonalizationProvider just knows what the WebPartManager wants.

Second offence? Too much has been pushed up into the base class. This is supposed to be the base class for all providers that deal with web part data persistence. And yet it has two API's. The first is the public API that the client (WebPartManager) calls to load and save the data, the one we'd like to see the path and user name passed into (Tell Don't Ask). This is the only API you should need to override in your provider implementation.

The second API is a couple of abstract methods that are expected to be used by provider implementations; they load and save the data formatted as a binary stream. These methods are what are actually overridden for the provider implementation. Interestingly enough, these abstract methods pass the page and username about. This should have caused some alarm bells to go off that the proper (public) API wasn't right.

What if you want to format the data differently? E.g. split it up and save it as plain text so you can search across it? Well, you can't. The base class, despite it's public API using the PersonalizationState class all over the place actually casts that to an instance of BlobPersonalizationState (which is internal and sealed so you can't override or even new it up) to do the formatting and pass the data on to the derived class to persist. Shocking.

Not to worry, You can just override the virtual public API and implement everything yourself, including finding the path and username. Except now you also have to implement that abstract protected API - even though you're not using it at all!

If the base provider class had been defined as an interface, or more derived classes had been implemented I'm sure this design wouldn't have happened. Better separation of responsibility and composition of helper classes would have sorted this right out.

A much cleaner design would have the base class as an abstract class. The SqlPersonalizationProvider (or any other) would get told the path and username. It could then call out to a helper class to get a binary stream to persist (being a helper class, other providers that only wanted to change the persistence store could be easily created). If you wanted to format the data differently, you couldn't use the same store, so you'd have to implement a new provider and you'd just use a different helper class (or format it directly in your new provider).

Is there a third offence? Yes, but this one has accomplices. Fire up Reflector and try and figure out how web parts data gets saved and loaded. It's an absolute mess of spaghetti. Just one example is that the WebPartManager creates a WebPartPersonalization item that uses BlobPersonalizationState that's the internal sealed class that handles the formatting that the PersonalizationProvider is using. It looks like a very confusing class structure that doesn't really know who has what responsibility and knows too much about the implementation details of the other classes, and assumes that the data will be formatted in such a way and used with the SqlPersonalizationProvider.

And the big problem? I want to use web parts on master pages in SingleUserBlog. Next time - how we can solve this.

Tags:

Comments (76) -

Franchises for sale
Franchises for sale United States
6/10/2009 6:50:44 AM #

It's interesting, the blog engine platform seems very variable in form.  My design skills are not so good as my C coding though, I would be interested in seeing what additional skins you can get for it.  Nice blog btw, best wishes for it and keep up the posts. Smile  Kind regards,  Peter sims.

Reply

suv reviews
suv reviews
7/20/2011 10:38:14 PM #

it ti permette di orientarti con semplicità nel pulviscolare niverso di Moncler.Troverai le indicazioni per lo spaccio o negozio Moncler più vicino a casa tua felpe moncler, pantaloni e abbigliamento sportivo.

Reply

ipad apps
ipad apps
7/24/2011 3:43:45 AM #

I've recently began a weblog, the data you provide on this site has helped me tremendously. Thanks for all your time & work.

Reply

dr dre headphone
dr dre headphone
10/30/2011 3:19:55 PM #

All I need is you needing me.

Reply

Beats Headphones
Beats Headphones
11/12/2011 10:44:43 PM #

Some neat info you have here, excellent work !!!

Reply

Supplier Tas Lokal Pasar Senen
Supplier Tas Lokal Pasar Senen United States
11/9/2013 6:24:30 PM #

you have a great blog here! would you like to make some invite posts on my blog?

Reply

philix
philix United States
11/19/2015 3:57:55 AM #

Nice Web Site

Reply

Philix
Philix United States
11/19/2015 6:57:14 PM #

superb web site.

Reply

philix
philix United States
11/20/2015 6:06:41 PM #

Great Web Site

Reply

philix
philix United States
11/21/2015 2:05:14 AM #

nice site.

Reply

Philix
Philix United States
11/27/2015 6:57:01 PM #

Wonderful Website.

Reply

Luvenia Colier
Luvenia Colier United States
1/6/2016 2:18:14 PM #

Congrats! This is such a great website, I know it will translate well into book form. Which is AWESOME!

Reply

Lidia Loser
Lidia Loser United States
1/15/2016 4:34:16 AM #

this is awesome like the book of awesome

Reply

Mitch Groene
Mitch Groene United States
1/15/2016 4:35:52 AM #

Congratulations on your success! You deserve it for brightening all of my work days with something to be excited about.

Reply

Leonel Marturano
Leonel Marturano United States
1/15/2016 5:15:07 AM #

The dolphin saving you one is the best one!

Reply

Tommy Burows
Tommy Burows United States
1/15/2016 5:45:28 AM #

Printing out an essay or paper, reading the first line and realizing there aren't any mistakes.<br />AWESOME!

Reply

Cornelius Styborski
Cornelius Styborski United States
1/15/2016 6:58:56 AM #

Congrats! So glad to see this site getting the recognition it deserves, the world can always use a little more awesome.

Reply

Rueben Derosa
Rueben Derosa United States
1/15/2016 8:20:30 AM #

I can't wait to read this masterpiece. Ordering off the menu at fast food restaurants and old dangerous playground equipment have to be in the book!

Reply

Rich Bowdry
Rich Bowdry United States
1/15/2016 8:27:48 AM #

Well good for you! I have a lot but one I just thought of was when you lick a crease of paper so that it'll rip in a straight line and it actually tears in a frayed straight line rather than rips awkwardly. I love that bleachy taste and that bleachy satisfaction.

Reply

Todd Mulgrew
Todd Mulgrew United States
7/20/2016 7:43:31 AM #

Wow very thorough article. Thanks

Reply

James Fly
James Fly United States
7/30/2016 8:14:27 AM #

This is such a great site come check out our new free Dating web site would wide fined your true love at http://youllfindlove.com/

Reply

Kristle Tongue
Kristle Tongue United States
8/25/2016 4:15:34 AM #

That's a  great post. I hope you will have a separate blog post for smart home and can you endorse a smart home builder.

Reply

wayback machine downloader free
wayback machine downloader free United States
9/8/2016 9:55:13 PM #

Thanks so much for giving everyone an exceptionally marvellous opportunity to read from this blog. It is often so amazing plus packed with a lot of fun for me personally and my office colleagues to visit your blog at a minimum 3 times every week to read through the latest things you have. And indeed, we're at all times contented for the breathtaking hints served by you. Certain 2 areas on this page are easily the simplest we have all ever had.

Reply

James Fly
James Fly United States
9/26/2016 12:25:10 AM #

Это такой хороший сайт с большим количеством полезной информации . Приходите присоединиться к нашему новый бесплатный социальный сайт, как Facebook . У нас есть группы друзей , объявления, сайт знакомств играть в игры бесплатно для всех на http://mysocialspot.ca/

Reply

apk file download
apk file download United States
4/5/2017 3:13:45 PM #

I have another website could fetch apk from Google Play: http://www.apksmart.com

Reply

cash for cars perth
cash for cars perth United States
9/21/2018 4:26:50 PM #

Very interesting topic, thanks for posting.

Reply

Roy Tanzi
Roy Tanzi United States
9/27/2018 6:55:05 PM #

There is noticeably a bundle to know about this. I assume you made sure nice points in options also.

Reply

Val Ammar
Val Ammar United States
9/27/2018 11:27:11 PM #

Hey! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us valuable information to work on. You have done a wonderful job!

Reply

Alecia Hacher
Alecia Hacher United States
9/28/2018 5:28:18 AM #

Hey, you used to write fantastic, but the last few posts have been kinda boring… I miss your great writings. Past several posts are just a little bit out of track! come on!

Reply

Aretha Varble
Aretha Varble United States
9/28/2018 8:36:20 PM #

There are very a great deal of details this way to take into consideration. That is a excellent denote bring up. I provde the thoughts above as general inspiration but clearly you will find questions such as the one you talk about the location where the most important thing will likely be in honest excellent faith. I don?t know if guidelines have emerged about items like that, but Almost certainly that a job is clearly defined as a good game. Both kids feel the impact of only a moment’s pleasure, for the remainder of their lives.

Reply

Bryon Buron
Bryon Buron United States
9/29/2018 2:35:12 AM #

There are a couple of fascinating points with time in the following paragraphs but I do not know if  all of them center to heart. There’s some validity but I most certainly will take hold opinion until I check into it further. Very good post , thanks and then we want a lot more! Included with FeedBurner at the same time

Reply

Margene Alstad
Margene Alstad United States
9/29/2018 10:22:43 AM #

Very nice post. I just stumbled upon your weblog and wanted to say that I've truly enjoyed browsing your blog posts. After all I will be subscribing to your rss feed and I hope you write again soon!

Reply

Amberly Duba
Amberly Duba United States
9/29/2018 2:04:20 PM #

I'm not sure exactly why but this site is loading extremely slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later and see if the problem still exists.

Reply

Lona Beresford
Lona Beresford United States
9/29/2018 6:25:30 PM #

Precisely  what I was  searching  for,  thankyou  for  putting up.

Reply

Eugene Klaren
Eugene Klaren United States
9/30/2018 1:43:54 AM #

I would like to see more posts like this!.. Great blog btw! Ohrid Subscribed..

Reply

24小時全日工作
24小時全日工作 United States
10/8/2018 12:20:00 PM #

互動性文字

Reply

Elden Steil
Elden Steil United States
10/9/2018 2:46:55 AM #

Hello my friend! I wish to say that this article is amazing, nice written and include approximately all significant infos. I would like to see more posts like this.

Reply

Jeanine Orlin
Jeanine Orlin United States
10/9/2018 9:32:43 AM #

I’m impressed, I must say. Really rarely do I encounter a blog that’s both educative and entertaining, and let me tell you, you've got hit the nail on the head. Your idea is excellent; the difficulty is one thing that not sufficient people are talking intelligently about. I am very comfortable that I stumbled across this in my search for one thing relating to this.

Reply

Emeline Rary
Emeline Rary United States
10/9/2018 7:16:48 PM #

Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your website? My blog is in the exact same niche as yours and my users would genuinely benefit from some of the information you present here. Please let me know if this alright with you. Thanks a lot!

Reply

Ezra Corl
Ezra Corl United States
10/10/2018 12:02:12 AM #

I like what you guys are up also. Such clever work and reporting! Keep up the excellent works guys I’ve incorporated you guys to my blogroll. I think it will improve the value of my website Smile

Reply

Gerald Isagba
Gerald Isagba United States
10/10/2018 5:32:11 AM #

Hey there! I've been reading your site for a long time now and finally got the courage to go ahead and give you a shout out from  Atascocita Texas! Just wanted to mention keep up the great job!

Reply

Malik Purpura
Malik Purpura United States
10/11/2018 8:03:40 AM #

Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how could we communicate?

Reply

Houston Ekman
Houston Ekman United States
10/11/2018 12:35:35 PM #

Hello! Someone in my Facebook group shared this site with us so I came to take a look. I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers! Fantastic blog and outstanding design.

Reply

Marcellus Serven
Marcellus Serven United States
10/11/2018 5:03:38 PM #

Hello! I know this is kinda off topic nevertheless I'd figured I'd ask. Would you be interested in exchanging links or maybe guest authoring a blog article or vice-versa? My site goes over a lot of the same topics as yours and I believe we could greatly benefit from each other. If you are interested feel free to shoot me an email. I look forward to hearing from you! Superb blog by the way!

Reply

永久脫毛
永久脫毛 United States
10/12/2018 4:53:41 AM #

全效保濕、打擊眼周細紋與皺紋。

Reply

Charlotte Borjon
Charlotte Borjon United States
10/12/2018 1:06:03 PM #

I’ve been exploring for a little for any high-quality articles or blog posts in this sort of space . Exploring in Yahoo I finally stumbled upon this web site. Studying this info So i’m happy to convey that I've a very good uncanny feeling I discovered exactly what I needed. I so much without a doubt will make certain to don’t fail to remember this website and provides it a look regularly.

Reply

Coleen Knoble
Coleen Knoble United States
10/13/2018 7:56:16 AM #

This would be the proper blog for anybody who wishes to learn about this topic. You know so much its almost challenging to argue along (not too I just would want…HaHa). You definitely put a whole new spin for a topic thats been revealed for several years. Wonderful stuff, just wonderful!

Reply

醫學美容 水動 cosmetic.wiki
醫學美容 水動 cosmetic.wiki United States
10/13/2018 10:56:23 AM #

John Hardy宣佈由Cara Delevingne擔任品牌代言人 - STYLE-TIPS.COM  John Hardy宣佈由來自英國的人氣超模Cara Delevingne成為品...      

Reply

Sherwood Rembold
Sherwood Rembold United States
10/14/2018 1:21:51 AM #

I really love the way you discuss this kind of topic.;’,-”

Reply

Antone Darby
Antone Darby United States
10/14/2018 11:27:23 PM #

Hi there! I know this is kinda off topic but I was wondering which blog platform are you using for this website? I'm getting sick and tired of Wordpress because I've had issues with hackers and I'm looking at options for another platform. I would be fantastic if you could point me in the direction of a good platform.

Reply

LISSAGE 【SKIN CARE】ホワイトニングプロテクターUV SPF33PA++的商品介紹   LISSAGE,SKIN CARE,ホワイトニングプロテクターUV SPF33PA+       

Reply

肌肉
肌肉 United States
10/16/2018 9:39:51 AM #

用洗面皂清潔肌膚-倩碧皮膚科專家的選擇。倩碧洗面皂可使肌膚保持清新,潔淨,舒適,無乾燥緊繃感。

Reply

GIORGIO ARMANI 亞曼尼 【黑曜岩新生奇蹟系列】黑曜石礦物修護精華 Mineral Restoring Serum的商品介紹   GIORGIO ARMANI 亞曼尼,黑曜岩新生奇蹟系列,黑曜石礦物修護精華 Mineral Restoring Serum       

Reply

Albert Hunze
Albert Hunze United States
10/18/2018 2:45:16 AM #

Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how could we communicate?

Reply

膠原控
膠原控 United States
10/18/2018 4:12:54 AM #

有關黑眼圈、黑眼圈成因、黑眼圈治療、眼袋手術、眼袋淚溝手術、淚溝、內開法脂肪下移筋膜修補、術前術後等一些詳細敘述或似是而非或有爭議的事項。

Reply

Noah Walund
Noah Walund United States
10/19/2018 1:03:29 AM #

I loved as much as you will receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get got an impatience over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this hike.

Reply

醫學美容 眼妝 cosmetic.wiki
醫學美容 眼妝 cosmetic.wiki United States
10/19/2018 1:09:28 AM #

延緩肌齡 - 卓意發展有限公司Crystal Mind Development Limited  延緩肌齡 - 卓意發展有限公司Crystal Mind Development Limited      

Reply

Jae Szlosek
Jae Szlosek United States
10/19/2018 9:01:30 PM #

hello there and thank you for your info ? I have certainly picked up anything new from right here. I did however expertise some technical points using this web site, since I experienced to reload the web site many times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I'm complaining, but sluggish loading instances times will often affect your placement in google and could damage your high quality score if ads and marketing with Adwords. Anyway I?m adding this RSS to my e-mail and could look out for a lot more of your respective exciting content. Make sure you update this again very soon..

Reply

Vincent Ogasawara
Vincent Ogasawara United States
10/20/2018 7:14:37 AM #

Heya i’m for the first time here. I came across this board and I in finding It truly helpful & it helped me out a lot. I hope to present one thing back and aid others such as you aided me.

Reply

Francoise Yoke
Francoise Yoke United States
10/20/2018 9:11:20 PM #

I was wondering if you ever considered changing the layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 pictures. Maybe you could space it out better?

Reply

Caprice Azcona
Caprice Azcona United States
10/24/2018 12:19:34 AM #

I've been absent for a while, but now I remember why I used to love this web site. Thank you, I’ll try and check back more frequently. How frequently you update your web site?

Reply

Football Solutions Numa Lavanchy
Football Solutions Numa Lavanchy United States
11/4/2018 9:29:20 AM #

Newcastle boss Chris Hughton has backed trouble striker Andy Carroll to star against West Ham despite being charged by police with attacking an ex-girlfriend. Chris Hughton backs Andy Carroll to overcome arrest and star against West Ham

Reply

Kate Mcgunagle
Kate Mcgunagle United States
11/6/2018 10:25:54 PM #

I’m impressed, I have to say. Really not often do I encounter a weblog that’s both educative and entertaining, and let me inform you, you've hit the nail on the head. Your idea is outstanding; the problem is something that not sufficient individuals are talking intelligently about. I'm very pleased that I stumbled across this in my search for one thing referring to this.

Reply

Andy Cawthorn
Andy Cawthorn United States
11/10/2018 10:27:36 PM #

Heya i?m for the first time here. I came across this board and I find It truly useful & it helped me out much. I hope to give something back and help others like you aided me.

Reply

Pedro Fennel
Pedro Fennel United States
11/11/2018 7:59:30 PM #

Thank you for the auspicious writeup. It if truth be told used to be a entertainment account it. Glance advanced to more delivered agreeable from you! However, how can we communicate?

Reply

Norman Bregel
Norman Bregel United States
11/12/2018 5:06:14 PM #

This can be a well written article, if only all bloggers offered the same value of content as you, the internet would be a far better place. Please keep it up!

Reply

Miquel Cius
Miquel Cius United States
11/15/2018 11:16:53 PM #

I harmonise with your conclusions and will thirstily look forward to your coming updates.

Reply

Jani Bergesen
Jani Bergesen United States
11/16/2018 7:51:03 PM #

Hey there this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I'm starting a blog soon but have no coding expertise so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!

Reply

Eliza Middlemiss
Eliza Middlemiss United States
11/16/2018 8:20:14 PM #

I used to be very happy to search out this web-site.I needed to thanks to your time for this wonderful learn!! I definitely enjoying each little bit of it and I have you bookmarked to take a look at new stuff you blog post.

Reply

Drusilla Rookard
Drusilla Rookard United States
11/16/2018 8:27:27 PM #

Hey there! Quick question that's entirely off topic. Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone 4. I'm trying to find a theme or plugin that might be able to resolve this issue. If you have any recommendations, please share. Appreciate it!

Reply

Ramiro Neelon
Ramiro Neelon United States
11/17/2018 1:40:15 PM #

My spouse and I absolutely love your blog and find a lot of your post's to be precisely what I'm looking for. Do you offer guest writers to write content to suit your needs? I wouldn't mind creating a post or elaborating on a lot of the subjects you write in relation to here. Again, awesome web site!

Reply

Jerrell Frecker
Jerrell Frecker United States
11/17/2018 8:56:41 PM #

Thank you for every other informative web site. The place else may just I am getting that type of info written in such a perfect way? I've a challenge that I am simply now running on, and I have been at the glance out for such information.

Reply

Rita Nutile
Rita Nutile United States
11/17/2018 10:50:02 PM #

The core of your writing while sounding agreeable originally, did not really work very well with me after some time. Somewhere throughout the sentences you managed to make me a believer but only for a short while. I still have got a problem with your jumps in assumptions and one might do well to help fill in all those breaks. When you can accomplish that, I will certainly be fascinated.

Reply

Temika Postemski
Temika Postemski United States
11/18/2018 7:07:12 AM #

I have read some good stuff here. Definitely worth bookmarking for revisiting. I wonder how much effort you put to create such a magnificent informative web site.

Reply

Babara Raciti
Babara Raciti United States
11/18/2018 10:40:31 AM #

Youre so cool! I dont suppose Ive learn anything like this before. So nice to seek out someone with some unique thoughts on this subject. realy thank you for beginning this up. this website is something that is wanted on the net, someone with a little originality. useful job for bringing one thing new to the internet!

Reply

Hiram Kettinger
Hiram Kettinger United States
11/18/2018 8:04:07 PM #

You actually make it seem so easy together with your presentation but I in finding this matter to be actually something that I believe I'd never understand. It seems too complex and extremely large for me. I am having a look forward in your next submit, I’ll attempt to get the cling of it!

Reply

Add comment

biuquote
  • Comment
  • Preview
Loading

Rel=Me

Month List

RecentComments

Comment RSS