Asp.net session details

Source: Internet
Author: User

Understand asp/asp.net programming understand asp/asp.net session model understand asp.net web application configuration file web. the role, significance, and usage of config understand the basic usage of internet information services (iis) and 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.

And "[asp.net] session details" related programming tips:

Strong> Locale. setFractionalDigits

Set the number of digits to the right of the decimal point, that is, the decimal precision.

Syntax

Public void setFractionalDigits (int value );

Parameters

Value

An integer that specifies the number of digits on the right of the decimal point, that is, the decimal precision.

See getFractionalDigits
 

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 information (this is an automatic function of the browser and the user will not notice it ), 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 %>

You can use the following sentence to learn about several pages you have browsed:

Some readers may ask: where does this seemingly array session ("...") come from? Do I need to define it? In fact, this session object is a built-in object of the www server with asp interpretation capability. 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 asp developers are currently using the powerful session feature, but they found that asp session has the following defects:

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 asp session defects, Microsoft designers have made corresponding improvements in the design and development of asp.net session, completely overcoming the above defects, making asp.net session a more powerful function.

Introduction to the web. config file some asp.net programmers say: What is the web. config file? I have never heard of it, but can the program I wrote work properly? Yes, you are right. Without the web. config file program, it 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 winntmicrosoft. netframeworkv1.0.3705.

The web application configuration file web. config is stored in various web applications. For example, if the root directory of the current website is inetpubwwwroot and the current web application is myapplication, the root directory of the web application should be: inetpubwwwrootmyapplication. If your website has only one web application, the root directory of the application is inetpubwwwroot. 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.

The session configuration information in the web. config file opens the web. config configuration file of an application, and 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 required attribute is

Attribute option description
Mode setting: Where to store session information
Off is set to not use the session Function
Inproc is set to store sessions in the process, which is the storage method in asp. This is the default value.
Stateserver is set to store sessions in independent State services.
Sqlserver settings store sessions in SQL server.

Optional attributes:

Attribute option description
Cookieless sets where the session information of the client is stored
Ture uses cookieless Mode
False uses cookie mode, which is the default value.
Timeout specifies the number of minutes after which the server automatically waives the session information. The default value is 20 minutes.
Stateconnectionstring is the name and port number of the server used to store session information in the status service, for example, "tcpip = 127.0.0.1: 42424 ". This attribute is required when the mode value is stateserver.
Sqlconnectionstring sets the connection string when connecting to SQL server. For example, "data source = localhost; integrated security = sspi; initial catalog = northwind ". This attribute is required when the mode value is sqlserver.
Statenetworktimeout sets the number of seconds after the session state is stored in stateserver mode and the TCP/IP connection between the web server and the server that stores the status information. The default value is 10 seconds.

In asp.net, the client session status is stored in the session model introduction above. You can find that the session status should be stored in two places: the client and the server. The client is only responsible for saving the sessionid of the corresponding website, while other session information is stored on the server. In asp, the sessionid of the client is actually stored as a cookie. If the user chooses to disable cookies in the browser settings, then he will not be able to enjoy the convenience of the session, or even access some websites. To solve the above problems, the client session information storage methods in asp.net are divided into cookie and cookieless.

In asp.net, by default, session information is stored on the client using cookies. If you want to use cookieless on the client to store session information, the method is as follows:

Find the root directory of the current web application, open the web. config file, and find the following section:

<Sessionstate mode = "inproc" stateconnectionstring = "tcpip = 127.0.0.1: 42424" sqlconnectionstring ="

Related Article

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: info-contact@alibabacloud.com 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.