Before reading this article, you need to understand the following knowledge. Otherwise, you may encounter different levels of problems in the reading process.
Understand ASP/ASP. NET Programming
Understand ASP/ASP. NET Session Models
Understand ASP. NET Web Application Models
Measure the test taker's knowledge about the functions, significance, and usage of the Web. config file for ASP. NET Web applications.
Measure the test taker's understanding about how to use Internet Information Services (IIS ).
Learn how to create a database in Microsoft SQL Server.
Session model Overview
What is a Session? Simply put, it is the number that the server sends to the client. When a WWW server is running, several users may browse the website running on this server. When a user establishes a connection with the WWW server for the first time, the user establishes a Session with the server, and the server automatically assigns a SessionID to the user to identify the unique identity. This SessionID is a random string consisting of 24 characters on the WWW server. We will see it in the following experiment.
This unique SessionID has great practical significance. When a user submits a form, the browser automatically attaches the user's SessionID to the HTTP header, which is an automatic function of the browser and is invisible to the user ), after the server processes the form, it returns the result to the user corresponding to the SessionID. Imagine how the server knows which user submitted the form when two users register simultaneously without SessionID. Of course, SessionID has many other functions, which we will mention later.
In addition to SessionID, each Session contains many other information. However, for ASP or ASP. NET Programming and programming, the most useful thing is to access ASP/ASP. NET's built-in Session object to store their own information for each user. For example, if we want to know how many pages a user visits our website browses, we may add the following to each page that a user may access:
- <%
- If Session("PageViewed") = ""Then
- Session("PageViewed") = 1
- Else
- Session("PageViewed") = Session("PageViewed") + 1
- End If
- %>
Some readers may ask: this seems like an array Session (".. ") Where can I define it? In fact, this Session object is a built-in object of the WWW server with ASP interpretation capabilities. That is to say, this object has been defined for you in the ASP system, and you only need to use it. The variable name in Session ("...") is like the variable name. In Session ("...") = $, $ is the variable value. You only need to write a sentence to access the value in the variable .. on every page of the user.
In fact, ASP has a total of seven built-in objects, including Session, Application, Cookie, Response, Request, Server, etc. Similar objects are also available in other server-side scripting languages such as JSP and PHP, but they are not the same in terms of naming or usage.
ASP Session functional defects
Currently, ASP developers are using Session, but they have discovered the following defects in ASP Session:
Process dependency: the ASP sessionstate is stored in the iisprogress, And the inetinfo.exe program is also used. When the inetinfo.exe process crashes, the information is lost. In addition, restarting or disabling the IIS service will cause information loss.
Limitations of the range of Session Status usage: when a user accesses another website from one website, the Session information will not be migrated. For example, there may be more than one WWW server on the Sina website. After a user logs on, he/she will go to various channels, but each channel is on a different server, what if I want to share Session information on these WWW servers?
Cookie dependency: in fact, the client's Session information is stored in the Cookie. If the client completely disables the Cookie function, it cannot enjoy the function provided by the Session.
In view of the above defects of ASP Session, Microsoft designers are designing and developing ASP. NET Session, and the above defects are completely overcome, making ASP. NET Session has become a more powerful feature.
Introduction to the Web. config file
Some ASP. NET programmer: Web. I have never heard of the config file, but can the program I wrote work properly? Yes, you are right, no Web. the config File program can run normally. However, if you create a large website, you need to make some overall configuration for the entire website, for example, you need to use the Web. config file. Although some options in the Web. config file can be configured through IIS, if the corresponding settings in Web. config also overwrite the configuration in IIS. In addition, the biggest convenience of the Web. config file is that you can access the settings in web. config by calling the System. Web namespace on the ASP. NET page.
There are two types of Web. config: the server configuration file and the Web application configuration file, both named Web. config. This configuration file stores a series of information about the web pages written in which language, Application Security Authentication mode, and Session information storage mode on the current IIS server. This information is saved using XML syntax. If you want to edit it, use the text editor.
The server configuration file takes effect for all applications on all sites on the IIS server.
In. NET Framework 1.0, the Web. config file of the server exists in \ WinNT \ Microsoft. NET \ Framework \ v1.0.3705.
The Web application configuration file Web. config is stored in various Web applications. For example, the root directory \ Inetpub \ wwwroot of the current website, and the current Web application is MyApplication, the root directory of the Web application should be \ Inetpub \ wwwroot \ MyApplication. If your website has only one Web application, the root directory of the application is \ Inetpub \ wwwroot. To add a Web application, add a virtual directory with the application starting point in IIS. The files and directories under this directory are considered as a Web application. However, adding a Web application through IIS does not generate a Web. config file for you. To create a Web application with a Web. config file, use Visual Studio. NET to create a Web application project.
The Web. config configuration file of the Web application is optional and optional. If not, each Web application uses the Web. config configuration file of the server. If yes, the corresponding values in the Web. config configuration file of the server will be overwritten.
In ASP. NET, modifications to Web. config will automatically take effect immediately after they are saved. You do not need to restart the Web application to take effect after modifying the configuration file in ASP.
Session configuration information in the Web. config file
After opening the configuration file Web. config of an application, we will find the following section:
- <sessionState
- mode="InProc"
- stateConnectionString="tcpip=127.0.0.1:42424"
- sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
- cookieless="false"
- timeout="20"
- />
This section describes how the application stores Session information. The following operations mainly aim at this configuration section. Let's take a look at the meaning of the content contained in this section. The syntax of the sessionState node is as follows:
- <sessionState mode="Off|InProc|StateServer|SQLServer"
- cookieless="true|false"
- timeout="number of minutes"
- stateConnectionString="tcpip=server:port"
- sqlConnectionString="sql connection string"
- stateNetworkTimeout="number of seconds"
- />
The above introduces ASP. NET Session
- DataList and Repeater controls of ASP. NET
- Analysis of IIS ing in ASP. NET
- Overview ASP. NET status types
- Introduction to ASP. NET and Web servers
- EnableViewState attribute of ASP. NET