ArticleDirectory
- 1. user-configured Performance
- 2. Configure how to store data
- 3. User Configuration and Verification
In ASP. NET 1.x, the only feasible way to store user information is to create your own data access component, which is useful. From ASP. NET 2.0, there is another option, that is, using user configuration. ASP. NET automatically uses a background data source to process data (read and update) of a specified user ).
In terms of concept, user configuration is very similar to custom data components, but it is more convenient to introduce. It is integrated with the ASP. NET authentication model. When necessary, the user information is automatically obtained. If the user information is modified, the current request is automatically written to the database at the end of the request.
Before using user configuration, You need to evaluate it carefully.
1. user-configured Performance
The goal of ASP. Net user configuration is to provide a transparent way to manage user information. You do not need to write your own database access using the ADO. NET data class.Code. Unfortunately, many features seem convenient, but the performance and scalability are not satisfactory.
The scalability of user configuration depends entirely on the amount of data you need to store and the frequency of data you plan to access.
The user configuration adds the lifecycle of a webpage in two ways:
- ProgramWhen accessing the user configuration object for the first time, ASP. NET Retrieves all the configuration data of the current user from the database. So far, no need to access the database for subsequent operations
- If any user configuration data is changed, the update will be postponed until the page processing is complete. After the prerender, prerendercomplete, and unload events release the current page, the user configuration is written back to the database.
The user configuration function is not integrated with the cache. Therefore, each request to use user configuration data requires a database connection.
The following two conditions are true and the user configuration has the best performance:
- Only a relatively small number of pages that access user configuration data
- Store only a small amount of data
On the contrary, the execution efficiency of user configuration will decrease:
- A large number of pages need to access user configuration information
- Store a large amount of information. If a request only requires a small amount of data, the efficiency will be lower (the user configuration model will always retrieve all the parts of the user configuration information)
2. Configure how to store data
In fact, how user configuration is serialized is the real limitation. ASP. NET's default user configuration provider serializes user configuration information into a data block and inserts it into the database as a separate field. For example, if the address information is serialized, the following result is returned:
Marty soren315 southpart drivelompoccalifornia93436u. S.
Another field indicates where each value starts and ends:
Name: S: 0: 11: Street: 11: 19: City: S: 36: 10: zipcode: S: 46: 5: Country: S: 51: 6
This method gives programmers sufficient flexibility to store any type of data, but it becomes very difficult to use it in other programs. Of course, you can write custom parsing code, but this process depends on your data volume and data type. The process may be very boring and lengthy.
In this private data format, the customer list cannot be created in other programs such as word, nor can the user configuration data or sorting be filtered by queries, you cannot query all users in a specified city. However, there are two solutions:
- Use custom data components instead of user configuration to store and retrieve data in the database
- Create a Custom User Configuration provider to store information using your database architecture
Solution 2 still allows your page to use the user configuration model. In fact, you can create a standard user configuration serialization scheme using sqlprofileprovider, and then switch it to a custom provider. You do not need to modify any code during the entire switchover. You only need to modify the Web. config configuration.
3. User Configuration and Verification
User Configuration and custom data components are naturally compared together. Obviously, data components are more flexible. It not only maintains user information, stores other types of information, but also executes more complex tasks.
Standard user configuration provider provided by ASP. NET (Sqlprofileprovider) Does not provide many additional features. The following list shows features that can be easily added by custom data components,Sqlprofileprovider.If you need any of these features, you have to discard the user configuration, or you need to create a custom user configuration program.:
- encryption : the user configuration data can be serialized as a string, XML, or binary, but it is still the original text data. If sensitive information exists, you only need to encrypt the information before storing it. As a result, you must put the encryption logic in your code, which is not expected to happen.
- Verification : you cannot restrict the information types stored in user configurations. You need to use other tools (such as verification controls or custom data classes) to prevent invalid data
- cache : you cannot save the information retrieved from the database in the memory, although it can be copied to the cache, however, it is very difficult to trace this information.
- review : when designing a custom data component, you can add any logon or tracking code. You can use this method to diagnose unexpected errors or monitor the performance of web programs. If you want to use this function in user configuration, you need to create a custom user configuration program and include the logon code.