Using a Personalization Provider


Using the personalization provider is actually pretty easy. All of the code that communicates directly with the provider is contained within the Web Parts set of controls and classes. This means that the only work you need to do is to configure the personalization database and modify the Web.config file to indicate the appropriate provider connection string.

Creating the personalization database is actually done by creating the Application Services database using the instructions in Chapter 25.

Open a Visual Studio 2005 Command Prompt window and type aspnet_regsql on the command line. You will be presented with the ASP.NET SQL Server Configuration Wizard. This wizard will prompt you for the location of a SQL Server instance as well as the credentials needed. You can also choose whether you want to create the Application Services information in a new database or configure an existing one. When you have completed this wizard, you will have created an Application Services database that hosts the data, metadata, and stored procedures required to support the membership, roles, profile, and personalization providers.

After you have created your Application Services database and you've verified that it is available and ready to be accessed, you need to modify your web application's Web.config file to point the personalization provider at this location. A sample Web.config configured for personalization is shown in Listing 26.1.

Listing 26.1. A Personalization-Enabled Web.config File

[View full width]

<?xml version="1.0"?> <configuration> <appSettings/> <connectionStrings>     <add name="AppSvcsConnection"      connectionString="database=ASPNET_AppServices; server=localhost;  Trusted_Connection=true;"/>   </connectionStrings>   <system.web>     <webParts>            <personalization defaultProvider="appSvcs">         <providers>        <add name="appSvcs"            connectionStringName="AppSvcsConnection"            type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"/>          </providers>       </personalization>     </webParts>     <compilation debug="true"/>   <authentication mode="Windows"/> </system.web> </configuration> 

This Web.config file indicates that the

System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider will be used as the personalization provider, and it will use the database indicated by the connection string named AppSvcsConnection.

Run an empty default.aspx in an application with the Web.config file from Listing 26.1 and see if it works. If no runtime errors occur while trying to load the default page, you can assume that a personalization connection was made to the database and you can continue on to the next section to create your first Web Part Page. If you do have errors, there is usually enough information in the error message to indicate what went wrong. Make sure to change the database and server options in your connection string to match the information you provided when you created the Application Services database using the aspnet_regsql wizard.



Microsoft Visual C# 2005 Unleashed
Microsoft Visual C# 2005 Unleashed
ISBN: 0672327767
EAN: 2147483647
Year: 2004
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net