Intimate contact asp.net (15) State Save

Source: Internet
Author: User

Asp. NET in the state saved in the ASP to save some sharing, personal status, using the application, session, cookies, these three kinds. Oh. In asp.net m$ In addition to inherit application, and give us a new state variable information, which is used to save the state of the Web control variables, very new, it must be quick to know:

Sorry, the knife is still from the original step-by-step. Start with the application. (stage under a roar), there is no way, in order to have a ladder sex, or should not be exposed to new things too soon:

Application

The application usage in asp.net is the same as the ASP, almost nothing to say, but it has two more particularly useful events, Application_onbeginrequest and Application_onendrequest. Their same as the original Application_OnStart and Application_OnEnd are placed in the global file (note that this file in the ASP name is Global.asa, in ASP.net is global.asax).

Note: This event, write not write on is the same. Like Application_End and Application_OnEnd are the same

Application_OnStart is the first event that is triggered in the entire ASP.net application, which is triggered when the first ASP.net program executes in a virtual directory, and Application_OnEnd is just the opposite. is triggered when the entire application is stopped (usually when the server is restarted/shutdown). Application_onrequeststart and application_onrequestend occur when every ASP.net program is requested, which means that the client accesses one ASP.net program at a time, and the two events are triggered. We can see his application from the following procedure. We first set up a global.asax, which reads as follows:

<script language= "C #" runat= "Server" >

void Application_onbeginrequest (Object sender, EventArgs E)
{
Response.Write ("Request is starting...<br>");
}

void Application_onendrequest (Object sender, EventArgs E)
{
Response.Write ("Request is ending...<br>");
}

</script>

Then put it in the root directory of this virtual directory, and then we randomly open an ASPX file, here we open the named.aspx file, see:

Figure 19-1

See no, above and below this page appears the statement we defined in Global.asax the request is starting ... and request is ending ... This is not the one we added to this file, and we will see its shadow in any asp.net file.

Session

Asp. NET in the session is I have seen the best processing, is other dynamic Web technology can not be compared. Asp. NET session no longer requires the support of cookies, which means that if the user closes the Cookie,session value, it can be saved as well.

However, we need to make some configuration of the Config.web file, where we find the text of the settings for the session, such as:

<sessionstate
Cookieless= "false"
/>

The cookieless= "false" to cookieless= "true", then the session will not be stored in the cookies, but stored in the URL.

Figure 15-2

The black circle above is the stored session value, of course, this is encoded, we can not know its straight real value.

In fact, I found that, do not change Config.web file, turn off cookies, do not use the URL can also pass the session value, this case is how to preserve the session, this is not very clear:

Session can also maintain the operation of the dead, that is, when the server is restarted, or can ensure that the value of the session is unchanged, but this will also change the Config.web file. is also set by the following statement.

<sessionstate
Inproc= "false"
server= "localhost"
Port= "42424"
/>
is not found here the session is very powerful AH: To change the localhost to the host you want, session can also be maintained on another host.



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.