WebParts on Master Pages

by Matt 6. September 2006 16:16

Last time I spent a very long time griping about how bad WebParts' PersonalizationProvider is, and how it doesn't support web parts on master pages. And I started off the post by saying that SingleUserBlog does just that. What gives?

Out of the box, the PersonalizationProvider doesn't support it, but it's really quite easy to add it. It's just not nice.

This is what Darren had already done in SingleUserBlog; derive from SqlPersonalizationProvider. Override the horrible protected methods I was grumbling about last time, and just call the base method, substituting the proper path with a constant string. Simple.

But what happens when you want to add a new provider? For example, an MS Access based one? When you add this provider, you add a runtime dependency to this provider. As soon as you derive from this protected method, you've added a compile-time dependency, and that's a whole different kettle of fish, and generally not something you take on lightly - after all, what happens if you also want to support SQLite, or just plain old xml? You can't just keep adding dependencies. On top of that, the MS Access providers are all sealed classes - you can't derive from there. (Fortunately, they come with source. Dodged the bullet this time.)

I came up with a slightly different, but only marginally better solution. Look at the docs for PersonalizationProvider and follow along at home. (And read the remarks section. This alone should show you that the class is messed up.)

I created a class that derives from PersonalizationProvider and takes as a parameter the name of the real PersonalizationProvider to use. It uses this name to look up the real provider in PersonalizationAdministration.Providers[]. It then defers nearly all methods to this provider. It allows the base class to handle load and save and overrides the dodgy protected methods. Here's where it gets messy.

When LoadPersonalizationBlobs is called, it uses reflection to call into the real provider and call it's implementation of LoadPersonalizationBlobs. The same happens for SavePersonalizationBlobs.

This works as well as the SqlPersonalizationProvider derived class. It avoids adding dependencies, and copes with sealed classes. But it's fragile - if the provider doesn't implement this hidden, protected API, you're stuffed. If your asp.net host doesn't allow reflection, you're stuffed. And above all, it's using reflection! Another bad smell - if you've had to use reflection to do something, you've probably already gone wrong.

So, what's the proper solution? Well, due to the messy design of the PersonalizationProvider, there isn't one. To support this very useful situation, you need to hack it. It's just a case of deciding how you want to hack it.

Because the PersonalizationProvider is responsible for selecting the path and username to save against, you have to create a new provider, which is a shame. You could make it slightly nicer by having it ask the WebPartManager (well, a derived version) that's sitting on the master page, what the values should be. But you still need a new provider.

I think SingleUserBlog's best choice is to use three methods. First, keep the SqlPersonalizationProvider derived class. You're deriving off a class in System.Web, so you're not adding any dependencies. Secondly, the reflection based method will work with what I suspect will be the majority of custom providers out there.

But my preferred choice would be to create a new provider from scratch for Sub. One of the main reasons I started using Sub was because it didn't use Sql Server for the blog data. So Sql Server shouldn't be the default provider for personalisation (or anything else) in Sub. It would be much nicer to have a simple xml based provider. This kind of provider wouldn't be much good in most other web apps - it won't exactly scale to a large site with loads of pages that loads of users could customise. But we know the usage it will get in Sub - one web page, customised by one user. Xml file should be able to cope with that. Given these requirements, I have no problem creating a Sub-specific provider for this.

Brendan's even got a head start on this (although it's not in the current codebase).


Comments (29) -

best suv 2011
best suv 2011
7/20/2011 10:38:09 PM #

Hi, just required you to know I he added your website to my Google bookmarks due to your layout. But seriously, I consider your net web-site has 1 in the freshest theme I??ve came across. It extremely helps make studying your blogging site significantly easier.


Meggan Monas
Meggan Monas United States
1/6/2016 2:33:37 PM #

Hey, congratulations Neil. This site really is something special and it's been a pleasure to share it with my readership too. Looking forward to future awesome things, and I'll send any suggestions that are sufficiently awesome.


Normand Schwarz
Normand Schwarz United States
1/15/2016 4:57:04 AM #

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


Isreal Payor
Isreal Payor United States
1/15/2016 6:44:19 AM #

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


Irvin Dewinter
Irvin Dewinter United States
1/15/2016 6:58:57 AM #

this is awesome like the book of awesome


Russell Schlappi
Russell Schlappi United States
1/15/2016 7:19:32 AM #

Let me be the first to say: Congrats, Neil! I've been following this site from day one, and have loved every single day of awesomeness that it has delivered. You deserve all the success coming your way. Keep it up!AWESOME!


Palmer Rinck
Palmer Rinck United States
1/15/2016 8:29:47 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.


Loida Shaneyfelt
Loida Shaneyfelt United States
1/15/2016 8:59:30 AM #

I love the dolphin saving you one.


Ramon Swaggert
Ramon Swaggert United States
8/25/2016 4:08:41 AM #

Times are changing and so as technology. We hope to find smart home architectural planners using the recent technologies available in the market.


so real 8 inch dong
so real 8 inch dong United States
9/12/2018 5:28:14 PM #

I discovered your site website on bing and check some of your early posts. Always maintain inside the great operate. I recently additional encourage RSS feed to my MSN News Reader. Looking for forward to reading more within you at a later time!…


水光槍 美白祛斑 水潤亮肌
水光槍 美白祛斑 水潤亮肌 United States
10/9/2018 1:05:28 PM #

「 生蛇 」( 醫學名稱是 『帶狀疱疹』Shingles ) 是由水痘病毒引起的疾病。水痘癒合後,病毒在神經細胞潛伏多年,日後隨時重新激活後導致的帶狀皮疹,就是「 生蛇 」。因此,凡感染過水痘的人,都有機會「 生蛇 」。病發時,身體某一部位會感到內疼或劇痛,通常是臉或背部及腰部的一側;這時由於病毒從脊髓處沿其中華一條神經擴散到身體以及去到連接的皮膚表面,形成紅疹及小水疱。帶狀疱疹疫苗Zostavax康栢苗 (蛇針)能助減低「 生蛇 」的機會,有效預防: 「 生蛇 」( 帶狀疱疹 ) 成效高達 70% 「 生蛇 」的後遺神經痛:即使紅疹痊癒,神經痛還可以持續數月或數年。年紀越大,持續有後遺   神經痛風險越高 「 生蛇 」引起的急性及長期痛症 不適用人士: 曾對疫苗成分包括明膠( Gelatin ) 及紐奧黴 ( Neomycin ) 有過敏性休克反應的人士 有原發及繼發性免疫系統問題的病患者,或正服用抑鬱免疫系統藥物(如高劑量膽固醇)的病人 患有肺結核,正發病及未經治療人士 孕婦


醫學美容 氦氖 cosmetic.wiki
醫學美容 氦氖 cosmetic.wiki United States
10/9/2018 10:32:30 PM #

雷神駕到!大展身手慶TAG Heuer擔任七人欖球賽官方計時 - STYLE-TIPS.COM  雷神Chris Hemsworth昨日到港並現身海港城,事關TAG Heuer的...      


填充 United States
10/10/2018 8:14:43 PM #



全面提供樓宇按揭貸款計劃及優惠,不限物業種類及樓齡,免收入証明及繁複的審查程序。 極具透明度及彈性. 24小時批核. 法例認可放債人機構.一按、二按、轉按、加按?無任歡迎 上市公司經營,信心保證,立即申請! 度身訂做借貸計劃.


隆鼻名稱 United States
10/17/2018 8:49:04 AM #



台南微整形-南臺灣醫美資訊: 署花強調醫美術後保養清潔防曬保濕  台南微整形-南臺灣醫美資訊: 署花強調醫美術後保養清潔防曬保濕      


shu uemura 植村秀 【臉部彩妝】UV泡沫CC慕斯SPF35PA+++的商品介紹   shu uemura 植村秀,臉部彩妝,UV泡沫CC慕斯SPF35PA+++6       


Eveline Staffieri
Eveline Staffieri United States
11/7/2018 2:46:53 AM #

Lovely blog! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also.


Stanton Stonecipher
Stanton Stonecipher United States
11/10/2018 10:04:04 PM #

fantastic points altogether, you simply gained a new reader. What would you recommend in regards to your put up that you simply made a few days ago? Any positive?


Cortez Mohler
Cortez Mohler United States
11/11/2018 11:18:10 PM #

Nice post. I was checking continuously this blog and I'm impressed! Extremely helpful information particularly the last part Smile I care for such information a lot. I was looking for this particular info for a long time. Thank you and good luck.


Adolfo Moscardelli
Adolfo Moscardelli United States
11/12/2018 6:00:38 PM #

Aw, this is an extremely good post. In thought I would like to put in place writing in this way moreover – spending time and actual effort to generate a top notch article… but exactly what can I say… I procrastinate alot and by no indicates often go completed.


Alecia Spach
Alecia Spach United States
11/15/2018 7:25:27 PM #

This is an amazing blog; I was trying to figure out how to keep in contact with your blog until I find out a decent iphone app for reading wordpress blogs. I really wish you to have a good day and keep with the good work!


Dominic Mckernan
Dominic Mckernan United States
11/16/2018 11:00:09 PM #

I’m impressed, I need to say. Actually not often do I encounter a blog that’s both educative and entertaining, and let me let you know, you have hit the nail on the head. Your thought is outstanding; the problem is one thing that not enough persons are talking intelligently about. I'm very comfortable that I stumbled across this in my search for one thing regarding this.


Abdul Gealy
Abdul Gealy United States
11/17/2018 12:22:18 PM #

I used to be very happy to seek out this net-site.I wanted to thanks to your time for this wonderful learn!! I definitely having fun with each little bit of it and I've you bookmarked to check out new stuff you weblog post.


Rod Kozera
Rod Kozera United States
11/18/2018 2:41:08 AM #

I've been surfing online greater than three hours nowadays, yet I by no means discovered any interesting article like yours. It’s lovely price enough for me. In my opinion, if all web owners and bloggers made just right content as you probably did, the web might be a lot more helpful than ever before.


Simone Grit
Simone Grit United States
11/18/2018 11:06:29 AM #

Hello, you used to write wonderful, but the last few posts have been kinda boring… I miss your tremendous writings. Past few posts are just a little out of track! come on!


Tempie Wassum
Tempie Wassum United States
11/18/2018 12:44:00 PM #

Hello my friend! I want to say that this post is awesome, great written and include almost all vital infos. I’d like to peer extra posts like this .


Stacy Milhorn
Stacy Milhorn United States
11/18/2018 2:10:55 PM #

It’s really a nice and useful piece of information. I’m glad that you shared this helpful info with us. Please keep us informed like this. Thanks for sharing.


Rickey Damien
Rickey Damien United States
11/18/2018 7:09:21 PM #

Wonderful blog! Do you have any tips and hints for aspiring writers? I'm hoping to start my own blog soon but I'm a little lost on everything. Would you recommend starting with a free platform like Wordpress or go for a paid option? There are so many options out there that I'm totally confused .. Any suggestions? Bless you!


Add comment

  • Comment
  • Preview


Month List


Comment RSS