Use user controls and custom Web components to personalize your portal

Source: Internet
Author: User
Tags comparison table control label custom name connectionstrings
Download the original code: WebParts.exe (619KB)
Source: ASP. NET 2.0 Personalize Your Portal with User Controls and Custom Web Parts

This article is based on the pre-release version of ASP. NET 2.0. All information provided in this article may change in the future.
This article will discuss the following:
Use Web components to create modular Web portal applications;
Personalized and custom features;
Use Custom User Controls as Web components;
Create personalized feature providers;
Portal applications are very popular today, and good portals share common and notable features. That is, it will provide visitors with elegant information, and this information is provided through a modular, consistent, and easy-to-browse user interface. Some comprehensive portals go further and even allow website Members to provide content, upload documents, and personalize portal pages.
Microsoft added a scalable portal application framework for the Windows Server 2003 platform, and then released a Windows SharePoint service, which provides some basic elements necessary for the portal application framework, this includes support for site members, content and document management, and modular presentation of data using Web components.
Web parts provide basic features that support custom and personalized features. In the Windows SharePoint service website, portal application users can add, configure, and delete Web parts so that they can easily personalize or customize pages. Websites based on Windows SharePoint service also provide a simple and powerful method to expand the site, that is, developing custom Web components. When creating a Web part that supports custom and personalized features, you just need to add some attributes and set several special labels in your Web part class. The tedious and complex work is done by the Web component infrastructure of the Windows Sharepoint service, such as serialization, storage, and reading of data related to site custom and member personalization features.
ASP. NET 2.0 introduces a set of Web component controls, which are similar to the functions provided by the Windows SharePoint service, they are designed to complete serialization, storage, and reading of data related to site custom features and member personalization features. However, they are more unique and flexible, and they are not tightly coupled with SQL Server or Active Directory. This is undoubtedly good news for companies that want to use form-based verification technology to create a portal or do not want to be limited by a specific database solution.

Figure 1: A sample portal application designed with modular Web Components
This article will show you how to use ASP. NET 2.0 Web parts development example portal application, the main purpose of which is to let you understand the portal application development Web parts, you will face some important design issues. First, we will introduce some basic concepts and control types involved in the new ASP. NET 2.0 Web part control set. For example, see Figure 1.
Web parts Basics
Pages used to place Web parts are called Web parts pages. 2. A Web Part Page requires a WebPartManager control (only one) and one or more WebPartZone controls. You can also include an EditorZone control or CatalogZone control (not required ). Note that. in the aspx file, the labels of the WebPartManager control must appear before any other control labels related to the Web Part infrastructure, such as the WebPartZone control, EditorZone control, and CatalogZone control. To better control the layout and presentation of Web Part pages, you can also use HTML tables in the aspx file to layout different zone controls in different places.

Figure 2: typical layout of a Web Part Page
Let's take a look at a simple Web Part Page example, which contains the WebPartManager control and WebPartZone control:

After a WebPartZone control is placed on the page, you can use the Web part definition to create a Web Part instance. There are two different ways to create a Web part definition. The first method is to create a class inherited from the WebPart class, and the second method is to create a user control. Later in this article, we will discuss in detail the differences between the two methods. Now, create a simple class inherited from the WebPart class (see figure 3 ).
Each Web Part instance is located on an index location of a specific WebPartZone control on a page. A WebPartZone control can contain multiple Web components. 4. The WebPartZone1 control contains two Web Part instances.

Figure 4: Web Components in a specific zone control
You can add Web components to a zone by programming and declaring them. Later, you can see how to add Web parts to the parts directory. After creating a CatalogPart control, you can add a new Web part to the WebPartZone control at runtime.
The method for adding a Web part to the WebPartZone control programmatically depends on the type of the Web part to be added. If it is a class inherited from WebPart, you must create an instance of this class programmatically and then call the AddWebPart method of the WebPartManager class. When calling the AddWebPart method, you need to input the following parameters: the Web Part instance, the target WebPartZone control, and the index position of the Web Part in the WebPartZone control. The Code is as follows:
// Create Web Part instance from WebPart-derived class
WebPart wp1 = new WingtipWebParts. HelloWorld ();
WebPartManager1.AddWebPart (wp1, WebPartZone1, 0 );
This allows you to add Web parts to WebPartZone programmatically. The declaration method is to define the control label in the. aspx file on the Web parts page. When a user accesses a page, if you want a Web part to appear in a specific WebPartZone control, you can add a ZoneTemplate to the WebPartZone control. The Code is as follows:

Don't forget to "Dress up" the Web parts, because if not, your Web parts will look boring. A common feature required by inline portal applications is to "skin over" the site and change the appearance of Web Components Based on the visitor's preferences. In the past, this meant you had to create your own architecture to support the function of changing the display mode of controls, which required a lot of work. ASP. NET 2.0 introduces the concept of "theme", which includes a series of style attributes and control attributes. These attributes can be applied to a single control, the entire page, or even the global scope of the entire application.
To make your portal application look elegant and professional, you need to customize the appearance of all WebPartZone controls, EditorZone controls, and CatalogZone controls. When you first do this, you will feel this kind of work is very boring. Because you need to skin and modify the display attributes for the content area, title bar, and dynamic menu of the Web parts, Editor parts, and Catelog parts. Fortunately, the new ASP. NET 2.0 topic features can extract the results of this. aspxfile interface work into reusable. Skin and. CSS files. The sample portal application of this article uses the skin swap and theme features to customize the appearance of Web parts. You can download it from the MSDN magazine website.
Display Mode and page range
A single instance of the WebPartManager control runs on each Web Part Page. It manages the Web Part instance and how the Web part interacts with the WebPartZone control. The WebPartManager control also provides a programmable interface to switch the display mode of Web Part pages. For example, you can switch between the following three modes: browsing mode, design mode, and editing mode. For example, to switch the current page to the design mode through a program, you only need to add a link control and set the DisplayMode attribute to DesignDisplayMode In the event processing program of this control. The Code is as follows:
WebPartManager1.DisplayMode = WebPartManager. DesignDisplayMode;
It is important to understand the differences between different display modes of Web parts pages. By default, the Web parts page is in browsing mode, which does not allow users to modify any Web parts. When you switch to the design mode, you can move Web Components inside WebPartZone or between different zones. Figure 5 lists all the display modes.
ASP. NET 2.0 Web Part Control generates all necessary DHTML and Javascript code in the background, allowing users to drag and drop operations in the browser. All other editing functions except drag-and-drop operations can be used in browsers that do not support required DHTML and Javascript features. This means that you do not have to worry about forcing all customers to use Microsoft IE5.0 or later browsers. The ASP. NET 2.0 Web parts control also allows you to manage the storage and acquisition of personalized data, so that you can remember where your Web parts were last placed.
In addition to code switching to display mode, the WebPartManager control also provides a method to allow switching between user range and shared range on Web Part pages. The page scope refers to whether to modify a Web part for custom operations or personalized operations. All users can see the results of custom operations, and only users can see the results of personalized operations. You can change the scope of a Web Part Page by calling the ToggleScope method of the WebPartManager control. The Code is as follows:
WebPartManager1.Personalization. ToggleScope ();
The default range is the user range. That is to say, modifications to Web components are recorded as personal operations and can only be viewed by the current user. Successfully calling the ToggleScope method will change the Web parts page to the shared scope. In this way, modifications to the Web parts will be recorded as custom operations. The purpose of the shared scope is to allow administrators or site designers to uniformly modify Web controls on the Web parts page so that all users can see this change. If there is a conflict, personalized modification always takes precedence over global custom operations.
The current user does not always successfully enter the sharing scope. By default, no user has such permissions. This permission is only granted to users in the Web. config file. The following is an example. It allows all users with the admin or site_designer role to enter the sharing scope and modify the global custom data:

Attributes and personalization
Each Web part object has a set of standard attributes that can be customized or customized. For example, each Web part has a Title attribute that can be customized after being added to WebPartZone. The EditorZone control and some Editor components allow users to modify Web part attributes.
When a user switches the Web Part page to the editing mode, the Web Part Menu provides an editing command. An EditorZone control is displayed when you call the edit command on a Web Part. This control is placed in the relevant Zone Control. ASP. NET 2.0 provides some built-in Editor components to modify the appearance, behavior, and layout of standard Web components.
By adding custom properties that can be personalized, Web parts personalized configuration data can be easily expanded. You only need to add these attributes in the definition of the Web Part class and add feature labels such as Personalizable, WebBrowsable, and WebDisplayName. After you complete this, the Web Part Control will help you store and obtain these personalized or custom attribute values.
When you create a personalized attribute, a private field is usually defined at the same time. The Code is as follows:
Private bool _ HR = true;
[Personalizable (PersonalizationScope. User), WebBrowsable, WebDisplayName ("
Show HR News "), WebDescription ("
Use this property to show/hide HR news ")]
Public bool HR {get {return _ HR;} set {_ HR = value ;}}
If you want to allow your users to personalize a property like this, you only need to add a PropertyGridEditorPart in the EditorZone control of the current page. Figure 6 shows what the user will see when you do this:

Figure 6 Editor parts allow users to personalize Web parts
If you define a Web Part property as a string or number, the PropertyGridEditorPart provides a text box for users to modify the property value. If this attribute is Boolean, The PropertyGridEditorPart provides a check box, as shown in figure 6.
Figure 7 shows an excellent programming technique learned from Web component development of the Windows SharePoint service: You can define a personalized Attribute Based on enumeration type.
The real value of creating WebBrowsable and enumeration-based Personalized attributes is that the PropertyGridEditorPart generates a drop-down list containing all optional attribute values, as shown in the Timeframe attribute in 7. This is convenient for the user and helps ensure that the user selects a valid attribute value.
There is one more thing worth noting about the Timeframe attribute. It is added with the Personalizable feature, whose value is PersonalizationScople. Shared. When an attribute is defined as a shared property like this, it can only be customized but not personalized. Since the shared property cannot be personalized, The PropertyGridEditorPart will not display this property when the current page is in the user range, but will only display this property in the shared range.
Web parts directory
We have seen how to add Web parts in advance in the WebPartZones control. You can also use another method to complete this function, that is, to allow users to add new Web Components at runtime. You can use the CatalogZone control and CatalogParts components, such as PageCatalogPart and DeclarativeCatalogPart. (See figure 8)
After you use this method to add a CatalogZone and CatalogPart, You can dynamically add Web parts at runtime, as shown in figure 9.

Figure 9: CatalogZones allows users to dynamically add Web parts
First, you need to understand the purpose of PageCatalogPart. In the design display mode or edit display mode, you can call the "close" command of the Web part. When a user closes a Web part, the Web part and the corresponding personalization or custom configuration are retained so that the user can add the Web part again later. Therefore, the PageCatalogPart control displays a list Of all closed Web parts. You can add them to the page again.
The "close" command is different from the "delete" command. The "delete" command appears in edit display mode. When a user deletes a Web part, all relevant information about the part, including custom and personalized data, will be deleted.
The DeclarativeCatalogPart can be declared to add a Web part. The code in Figure 8 illustrates how to define this directory, where WeatherWebPart, which uses a custom name, is used. With this method, you can provide users with a variety of Web components.
As a supplement to this article, we recommend that you read "Introducing the ASP. NET 2.0 Web Parts Framework. This section provides more detailed information and a complete example of using EditorZones and CatalogZones to create a Web control page. Stephen also talked about more advanced topics, including Verbs, Connections, and Web component import and export.
ASP. NET 2.0 portal application development
In addition to the architecture of Web Components, some new features in ASP. NET 2.0 make the development of internal portals more attractive. As mentioned earlier in the article, the introduction of theme and skin replacement allows style attributes to be conveniently and directly independent from portal pages. You can make a unified style change without having to modify each page. Of course, what is even more exciting is the introduction of Master Pages. With the master page, you can place the overall WebPartManager control and all WebPartZones controls on a separate template page. Other pages can inherit these basic appearances and functions. In the example portal application, an interesting technique we use is to add a ContentPlaceholder control to the ZoneTemplate template of each WebPartZone control on the master page. In this way, you can use this content control to add your own Web components on the content page of this master page and map them to the corresponding ContentPlaceholder control.
One thing you must consider when designing a master page for a portal website is to provide users with custom features. As you can see, based on the different types of zone controls contained in the page, there are several different ways to modify the custom mode of the page for users to choose from.
One way to display custom options to users is to encapsulate the WebPartManager control and a series of buttons (typically LinkButton) into a user control, and then place the control in the master page, you can provide custom options for all pages on the website. If your website has more than one master page to provide different la s for different pages, encapsulating it as a user control (we can call it WebPartManagerPanel) is also very useful. The menu bar of the portal application shown in Figure 1 provides an example user control to display the display mode and range of the current WebPartManager, some linkbuttons are also provided to change the page to one of the editing modes supported by the WebPartManager control. (This is the user control used by the sample portal application ).
Another useful feature in your WebPartManagerPanel control is to display or hide corresponding display mode menu items based on the current user and the current page. You can view the supported display modes in the SupportedDisplayModes collection attribute of WebPartManager to display or hide the corresponding display mode menu items. For example, to check whether the current page supports CatalogDisplayMode, you should write the following code:
If (WebPartManager1.SupportedDisplayModes. Contains (
WebPartManager. CatalogDisplayMode )){
// Enable catalog display mode LinkButton here...
It should also be noted that if the current user does not have the corresponding permissions, calling ToggleScope will fail. Therefore, it is a good idea to use code to determine whether to display or hide the interface elements that allow users to enter the shared scope. You can query the CanEnterSharedScope attribute of the Personalization attribute of the WebPartManager control to achieve this. The Code is as follows:
If (WebPartManager1.Personalization. CanEnterSharedScope ){
// Display UI element that allows user to enter shared scope
The WebPartManagerPanel user control in the example application included in this article contains a complete implementation, which can dynamically adjust the display of the pane based on the current user and the current page capabilities.
Use user controls as Web Components
When using the Windows SharePoint service to create Web components, the most frustrating thing is that you must use code to create the entire interface of the control. The designer cannot help at all. Because many Web components are composed of a series of interactive server-side controls, it is unfortunate that you cannot use the Visual Studio designer when creating Web components. An obvious solution is to allow developers to create user controls and use them as Web components. (A third-party tool named SmartPart provides the ability to use user controls as Web Components in the Windows SharePoint service ).
ASP. NET 2.0 Web components solve this problem. It allows any controls to be used directly as Web components without modifying or packaging these controls. This not only combines user controls into the Web parts set, but also easily integrates the custom controls used in the existing page.
The internal working principle of this method is that if a standard control (not a Web Part) is added to the WebPartZone control, the system will implicitly call WebPartManager. createWebPart method. This method creates an instance of the GenericWebPart class and initializes the instance with the added control. GenericWebPart inherits from the base class WebPart and provides the core Web Part attribute implementation. When building the GenericWebPart control, it adds the initialized control as a child control. In the page rendering process, like most composite controls, GenericWebPart itself does not output any content in the response cache, but serves as a proxy for outputting the sub-control content. The final result is that you can add any control to the WebPartZone control on the page without worrying that it will not run. For example, the following page defines a WebPartZone control, which includes a user control and a standard calendar control, both controls are implicitly packaged into a GenericWebPart control. The Code is as follows:

Like standard Web components, it is also possible to dynamically create controls encapsulated by GenericWebPart. For a user control, you must first call Page. LoadControl to dynamically load and create a user control instance. Second, you must explicitly set a unique ID for this control. In addition, you must call the CreateWebPart method of the WebPartManager object to create a GenericWebPart class instance to encapsulate the user control instance. Finally, pass the reference of the obtained GenericWebPart instance as a parameter to the AddWebPart method and specify the WebPartZone to be added. The Code is as follows:
// Create Web Part instance from User Control file
Control uc = this. LoadControl (@ "webparts \ CompanyNews. ascx ");
Uc. ID = "wp2 ";
GenericWebPart wp2 = WebPartManager1.CreateWebPart (uc );
WebPartManager1.AddWebPart (wp2, WebPartZone1, 1 );
The only drawback of this technology is that you cannot control some special features of Web parts, because your control is not inherited from the WebPart class, and only GenericWebPart is inherited from the WebPart class. Once you run a page containing controls encapsulated by GenericWebPart, you will immediately find a phenomenon that most Web components are not expected to be untitled by default, there are no related icons and descriptions. Figure 10 shows a sample user control wrapped by the GenericeWebPart control with a default title (no title) and a graph.

Figure 10 GenericWebPart
One solution is to add an Init event processing routine in your user control. If your control is encapsulated by GenericWebPart (the type of the Parent attribute can be determined by querying), you should set some attributes of the GenericWebPart class in the program. The Code is as follows:
Void Page_Init (object src, EventArgs e ){
GenericWebPart gwp = Parent as GenericWebPart;
If (gwp! = Null ){
Gwp. Title = "My custom user control ";
Gwp. TitleIconImageUrl = @"~ \ Img \ ALLUSR. GIF ";
Gwp. CatalogIconImageUrl = @"~ \ Img \ ALLUSR. GIF ";
When you run this page again, once the user control is encapsulated by GenericWebPart, modifications to the attributes of the GenericeWebPart parent control are reflected on the Web Components that contain your control. Figure 11 shows a new property-based user control. Note the title and icon.

Figure 11 Title and icon
Another more attractive solution is to implement the IWebPart interface directly in your user control class. Since the user control never directly queries the properties of Web parts, because the information is processed by the GenericWebPart class, it seems that it is useless at the beginning. Fortunately, the designers of the GenericWebPart class are aware of this requirement. If the control implements the IWebPart interface, the property in the GenericeWebPart class will be automatically delegated to the encapsulated control.
Therefore, customizing the Web part feature of a user control is only to implement the IWebPart interface and fill in the seven attributes defined in the interface. The code in Figure 12 provides an example of the background code class of the user control, implementing the same result as the previous dynamic modification of the GenericWebPart attribute.
You may also consider creating another base class for your user control. This base class inherits from UserControl and implements the IWebPart interface, then it can be inherited by all the user controls in your portal application. This is what we did in the example application of this article. In this way, your user controls can initialize the required attributes in their constructor, and others are controlled by the base class. Figure 13 shows a user control base class implementing the IWebPart interface and a code corresponding to the background class. The user control uses this base class to set the title and icon attributes.
Now that you have the flexibility to create user controls, you may ask: When you have user controls supported by the designer, you can also customize Web part features, why do we need to create custom controls? In fact, you need to do this for several reasons. One of the reasons is that you cannot add a defined action (verbs) to the user control ). To do this, you must directly inherit from the WebPart and then rewrite the Verbs attribute. Of course, you can also consider implementing the IWebEditable interface in your control.
Another reason is that the user control is limited to the application directory unless you. the ascx file is copied from one project to the directory of another project. Otherwise, you cannot share the user control in multiple Web applications. On the other hand, the custom Web Part class inherits from the WebPart class and can be compiled into a reusable dll and deployed to the Global Assembly Cache (GAC ). Another point is that by customizing the Web parts class, you can also write a custom designer for your controls to change the default appearance in Visual Studio, you can also create an icon when this Web Part class is placed in the toolbox. Figure 14 provides a feature comparison table that allows you to choose whether to customize Web components or user controls.
Web parts and personalized feature provider programs
The Provider Program is ASP. A new feature of NET 2.0, this is also one of the main reasons why you can see that so many built-in functions and complete controls can run with little or no code. The basic idea behind the Provider Program is to define a set of common data-related tasks for a specific feature and aggregate those tasks into an abstract class declaration, this abstract class inherits from the common ProviderBase class. In the personalization features discussed in this article, the data-related tasks that must be clearly provided include:
Saves the attributes and layout of Web parts for a specific page or user;
Loading the attributes and layout of Web parts for a specific page and user;
Saves General Web Part attributes and specific page la S (for general customization );
Load General Web Part attributes and specific page la S (for general customization );
Resets the attributes and layout of a specific page and user's Web parts to their default values;
Resets the Web Part attributes and layout of a specific page to its default value (for general customization );
Some other features that are affiliated with the personalized architecture also require the capability of persistent storage, but they can basically be attributed to the above six requirements. If we assume that a class can complete these six actions and successfully save and restore data, when the site is running, the WebPartManager control on each page can use that class to save and restore all personalized and custom data. The abstract class defining these methods is called the PersonalizationProvider class. By default, a specific derived class is used as the SqlPersonalizationProvider class. Figure 15 shows the three methods that represent the six features we have defined. Note that, whether or not the entered userName parameter is null, each method can personalize or share user-defined data.
All personal data is saved as normal binary data (byte []). The default SqlPersonalizationProvider class will write the data into an image field in the database. Since ASP. NET 2.0 knows that a class can provide these methods, it can create more logic in the basic control set than before. In our case, the WebPartManager class on each page that uses Web parts is responsible for correctly calling the current PersonalizationProvider class to serialize and restore personalized settings for each page. Figure 16 shows how the EditorZone control interacts with the default SqlPersonalizationProvider class.

Figure 16 Interaction
The more you use ASP. NET 2.0, the more you will know about the provider architecture. For example, there are many providers, such as member providers, role management providers, site map providers, and site monitoring providers. All provider programs define a similar core method set for interaction with controls.
Modify personalized data storage
Like most provider programs in ASP. NET 2.0, the default personalized provider program is implemented for SQL Server background storage. If the configuration file is not modified, the default SqlPersonalizationProvider uses the SQL Server 2005 Express Edition connection string and supports local file-based databases. The connection string is like the following:
Data source =. \ SQLEXPRESS; Integrated Security = SSPI;
AttachDBFilename = | DataDirectory | aspnetdb. mdf; User Instance = true

One advantage of using the SQL Server 2005 Express Edition file-based database is that it can be dynamically created without any additional settings. This means that you can build a new site and enable personalized features without setting up databases! When you first interact with the website, the system will generate a new aspnetdb in the App_Data directory of the site. mdf file, and initialize the database with tables and stored procedures that support all default provider programs.
This is great for small sites that do not need to scale up or support many concurrent users. However, for enterprise systems, data must be stored on a fully managed and dedicated database server. Fortunately, it is very simple and straightforward to modify the database used by SqlPersonalizationProvider. The SqlPersonalizationProvider configuration initializes the connection string to LocalSqlServer, which means that it will Find the configuration item named LocalSqlServer and use the relevant connection string to open the connection to the database. By default, this string is what you see above, meaning it will write a local SQL Server 2005 Express Edition. mdf file. To modify it, you must first clear the LocalSqlServer connection string set and reset a new connection string value in your Web. config file. (Or you can modify the Machine in the Machine range. config file to affect all the sites on this machine) The following is a Web. config File example, which modifies the provider Database Value to point to a local SQL Server 2000 instance:


Before the modification takes effect, the local SQL server must have a database named aspnetdb, which contains the tables and stored procedures required by SqlPersonalizationProvider. With ASP. NET 2.0, a tool named aspnet_regsql.exe is released, which can be used to create this database. When you run the program with the default settings, it will create a local database named aspnetdb, which has all the tables and stored procedures required by the provider program, alternatively, you can install these tables and stored procedures into an existing database. The names of all tables and stored procedures start with "aspnet", so they are unlikely to be repeated with any existing tables.
And all ASP. like the Provider Program of NET 2.0, this indirect mode provides a very flexible architecture that allows you to completely replace the backend data storage without modifying any page or Web components.
Create your own personalized Provider Program
It gives you a certain degree of flexibility to modify the connection string for the personalized Provider Program. However, the SqlPersonalizationProvider still uses the namespace System. Data. SQL. Client function to access Data. This means that you must use the SqlServer database. If you need to save personal data to another database, or it may be another completely different data storage, you will have to go further, create your own personalized data provider. Fortunately, most difficult jobs are ready for you and easy to use. As an example of storing personalized data to another type of data storage, the example portal website in this article has a complete implementation of a custom provider program named FileBasedPersonalizationProvider class, it saves all personal and custom data to a local binary file under the App_Data directory of the application. The name of the binary file is generated by each user and path, and each path has a unique and common user configuration file.
To create a custom personalized data provider, you must first create a new class inherited from the PersonalizationProvider base class, and then override all the abstract methods inherited from the base class. The class definition shown in Figure 17 demonstrates how to do this.
To make your provider program operational, there are only two important methods that must be implemented: LoadPersonalizationBlobs and SavePersonalizationBlob. These two methods complete the binary serialization of personalized data. When a page is loaded, the personalized architecture calls them. When the Web Part Page is in editing, directory, or design mode, if the data is modified, the personalized architecture also calls them to write the data back. (Typically, it is based on a specific user ).
In the sample code downloaded, the implementation code of SavePersonalizationBlob writes the dataBlob parameter to a file based on the input user name and unique path name. Similarly, the LoadPersonalizationBlobs implementation code searches for this file (using the same naming method) and returns a user-defined or shared blob data. If the input userName parameter is null, both methods will save or load shared data by default. If it is not null, user personalized data will be saved or loaded. Figure 18 shows the implementation code of the two methods in the example FileBasedPersonalizationProvider, and a pair of helper methods used to generate a unique file name based on the user name and path information.
Once the Provider Program is fully implemented, you can register it as a provider program through the provider section in the personalized configuration section. To actually use it, you must define it as the default personalized provider in the Web. config file. The following is an example of using our custom file-based Provider Program as the default provider:

If we re-run our website, all personal data will now be stored in a local binary file. Obviously this is not the best solution, but the sample code provides some ideas to let you know how to implement your own personalized provider, no matter what type of backend storage you want. Figure 19 shows how our new provider is inserted into the entire Web component architecture.

Figure 19 use FileBasedPersonalizationProvider
Further steps
So far, you have seen that if ASP.. NET 2.0 and its new Web component control to create portal applications with rich features that support customization and personalization, while ASP. NET 2.0 makes this work quite simple. Perhaps the most important feature of this architecture is plug-in capabilities. The provider architecture makes it easier to write personal data that meets the characteristics of your site to the backend data storage, and will not be bound to a specific serialization implementation or data storage. So now let's move forward and use ASP. NET 2.0 Web components to create custom sites!
If you like this article, there are a lot of things to learn to create Web parts in the ASP. NET 2.0 portal application. Remember to download the sample code from the MSDN magazine website. Some examples can be used in ASP. NET 2.0 QuickStart tutorials. We also recommend that you read Fredrik normé n's blog, which contains some interesting examples of ASP. NET 2.0 Web components.

Author Profile
Ted Pattison is an expert and trainer who provides some easy-to-use training courses through Pluralsight, offers consulting services through Ted Pattison Group, and author of several books.
Fritz Onion is a partner of Pluralsight. Pluralsight is a company engaged in education and content creation. It focuses on ASP. NET Web development, and Fritz is also the author of Essential ASP. NET (Addison Wesley 2003. You can view his website on

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.