Personalization is now a key part of most Web applications. TechRepublic and Amazon are typical examples of the ability to remember certain features of a user. Applying ASP.net 1.x to implement this functionality requires some extra work and a session object to be used, but the 2.0 version simplifies the personalization process.
Personality files
The ASP.net 2.0 Profile system allows you to easily store information about users. You define attributes that are related to each user and store them in their personality files. Personalized file data can be easily accessed by program. As with other save files, it must be stored and the personalized file uses SQL Server by default.
Profile systems are based on provider models, and special profile providers are responsible for serializing and serializing attribute values to a data warehouse. The. NET framework uses a SqlProfileProvider class by default, which uses a SQL Server database tables to store data.
System Configuration
Before using the ASP.net 2.0 personality file feature, the Web server must be properly configured to support this feature. By default, the personality file feature uses a SQL Server terminal, but you can also create your own provider. In this article, I mainly discuss the standard SQL Server terminal, which uses the default SqlProfileProvider class.
SQL Server supports versions 7.0, 2000, and 2005. To configure a system that supports SQL Server, first configure the database server, and finally the ASP.net platform.
The. NET Framework 2.0 contains tools to properly configure the ASP.net environment. If you use SQL Server 2005 Compact and Visual Studio, you do not have to configure it. If the above program is not applied, the first step is to register a SQL Server connection. You can do this by using the command-line tool Aspnet_regsql.exe installed with the. NET Framework. On my machine, the path to this tool is:
C:\Windows\Microsoft.NET\v2.0.50727\aspnet_regsql.exe
This tool contains a number of options that you can use with command-line options (-?) Read more. In my development system, I use the existing SQL Server 2000. The following command configures the environment by establishing the necessary database on the specified server.
Aspnet_regsql.exe–a P–e–s Database_server_name
Command line switch E tells the system to authenticate with the current user certificate. The switch s allows you to specify the database server name. Switch a indicates which option to add, and the following p indicates increased personality file support. You can build a SQL Server database by executing this command. The default name for the database is ASPNETDB, but you can also use the command line switch D to undo it, and Switch D allows you to specify an existing database.
Now that you have a SQL Server environment in place, you should then configure ASP.net 2.0 to take advantage of connections and personality files. You can activate ASP.net environment properties by entering the IIS management interface, viewing the ISS Web site Sites Properties, and selecting the ASP.net tab. Select the Edit Configuration button on the ASP.net tab. The validation (authentication) tag contains a role (Roles) area in which role management (roles Management) is activated (this should be viewed). The default SQL Server (localsqlserver) connection string is specified in the generic (general) tab. My development environment uses the following connection string:
Data source= database_server_name;integrated Security=sspi;
Initial Catalog=aspnetdb; User Instance=false
Save these changes in the ASP.NET environment and connect it to the previously configured instance of SQL Server. Once you've configured the platform, you can start executing.
Defining elements
The data elements used in the personality file are created and saved in the Web.config file (that is, the saved data values are defined in that file). The actual value (for different users) is stored in a terminal Data warehouse. You can specify the name of each attribute, the type of data, and how data is serialized.
The data type of the attribute is associated with the. The valid standard data types in net are the same. Serialization options generally depend on the data type being stored, but there are four serialization options:
ProviderSpecific: The default profile provider determines how the property value is serialized.
String: The property value is converted to a string.
XML: The property value is converted to an XML form.
Binary: The property value is converted into binary form.
The personality file element defined in the attribute element is contained in a Web.config file element, which is located in the system.web portion of the file. The web.config in list A includes a piece of personality files that are supported by the previous personality file. It will use two personalized file entries--firstname and lastname--them to save string values and allow anonymous users.
Personality file characteristics can be applied to both anonymous and authenticated users. The previous Web.config file uses the AllowAnonymous attribute of the personality file element and activates the application anonymous support (anonymousidentification Element) to specify anonymous support.
Using Code
After the proper configuration of the environment, you can easily in your. NET code to apply the element of the personality file. The simple C # code in List B uses a personality file element to store and display data values, taking advantage of the profile class contained in the System.Web namespace. The code contains the asp.net file after the code separates the file.
List C contains code separation (codebehind) for custom code. The first button stores the value of each text field in the Personality file field. The second button restores the values from the Personalization file field and populates the text fields with these values.
Personalized More Simplified
Personalization is just one of the many new features of ASP.net 2.0. After several configuration steps, you can easily add personalization features to your application by coding the standard Web.config files and profile classes.