次の方法で共有


ASP.NET 2.0 and Web Parts

One of the coolest features of ASP.NET 2.0 is the ability to create web site that can host “web parts”. This allows you to create sites where the content on the pages can be customized by users themselves. Think of portals sites such as MSN , etc (check out https://my.msn.com/ if you have not seen it), where you can set the types of news you are interested in, the weather forecast for where you live, and so on, and you get the picture. All the different elements that make up one of these personalized pages are know as web parts.

I’d worked previously with web parts in Windows SharePoint Services (WSS) in Windows Server 2003, and they are very good, and WSS makes it very easy to get a portal up and going. ASP.NET 2.0 takes this concept, and makes it more generally available to developers to build and work with them in a wider range of scenarios.

One of the best articles I have seen on ASP.NET 2.0 Web Parts is in the current September issue of MSDN in the article “Personalize Your Portal with User Controls and Custom Web Parts”. It takes you through the background, how it all works, has a nice sample portal you can download and check out yourself.

The sample they include has some nice features. They create a WebPartManager user control that shows the valid modes, and is used to change mode. They use themes and skins to give the site a consistent look and feel. They define a new base class for user controls that implements IWebPart, to make it easy to build User Controls that work well as WebParts.

The only bit I had problems with was the personalisation. The sample portal includes its own provider for the data store, based on a flat file, rather than a data base, just to show it could be done. For some reason I just couldn’t get it to work (even after un-commenting the provider entry in the web.config file), and it’s sort of strange they included it, as its not really part of web parts. In the end I let the system create a new database, and added a appropriate use via the Web Site Administration Tool.

There are also a couple of different master pages in the project, which show off different techniques for handling page design, but its not clear how you test them out, so it looks like a “readme” note would not go amiss here.

Anyway, enjoy!