inicio mail me! sindicaci;ón

Skill of the Session in ASP

Had written a little a bit larger the person of ASP knows, session this boy or girl friend is really good with, it can use variable of data of some of illicit of the person that the record is used, already safety goes to the lavatory again. But you know Session really run a principle? After understanding probably, you also dare use the target that this your person loves to be hated again again not quite again. Although turn and replace the method disrelishs a trouble a bit, but it is under quantity of long end-of-term examination, also must so did.

Will say the benefit that says Session above all, it can use record client to carry variable of illicit some data, and won’t disappear inside time limits. This is very main function really, the system that has a member especially must want to be used. Resemble be a member recording date of enter an item in an account, time, condition and the real time data of lots and lots of this records the commodity ﹞inside the shopping basket of the person that ﹝ is like shopping system record to use, private institute needs the person that these information belong to each to use, normally developer is processing of use Session record.

However, the Session in ASP is to use Cookies place to form, the data that the server will record inside all Session, pass to the browser of the user with the means of Cookies. Normally general browser can put these Cookies rise, dot of the person that use every time is chosen concatenate, do with the server again online when, the browser can pass these Cookies Server is handled for doing. This is Session namely run a principle, when data amount is a bit larger, because must be passed,close again, not only have circuit frequency wide, efficiency is reduced relatively, because Server must cost more resource,making the initiative motion such as online processing and new configuration memory. You may think now ” I must use this function, be forced to sacrifice nodded ” , nevertheless the article tells Session is to teach everybody to be used less on one hand; It is to have of course on the other hand replace method, tighten what enter the court then, it is the Application object inside congeneric Global.asa.

Application also is the ace that the record processes provisional data, the ability of each respect and usage are mixed Session is same, just than below, the data that it records is to belong to public, namely the variable space that the person that any use can share. Application unlike Session, either transmit the data the person that use, etc the next time online reread is taken, it is to record the memory on Server directly, opposite under on efficiency go up quickly Session a lot of.

Because Application object is public, must do above all, want to plan a public section to the person that use individually namely, the area that lets every user have his can record a data, emulate the purpose of Session in order to achieve. There are two kinds of ways now:

One, when Server activations beforehand initialization is built reach allocate space of memory of the person that use, normally this is planted the practice although one Server switched on the mobile phone to take a lot of resource first, but also leave out the person that use every time later is online must make distributive trouble. But have a restriction, use this kind of method to must limit the largest number, because be one activation with respect to initialization, we can beforehand the memory space that appraise builds some amount, so this kind of method is used at chatting normally room on program of this kind of diminutive.

2, this kind of method is more appropriate to should calculating for large application process, the allocation that uses trends law, first time of the person that should use is online just begin to allocate resource to give this the user to Server. These two kinds emulate the plan of Session, the purpose is those who reduce Session resource use up, but still cannot replace completely after all, we or need use little Session, can have reduced many burdens to Server at least.

■ case of one party

Above all the fact that we begin the first program is made, because be Application of the initialization when activation, we want to begin from inside Global.asa of course:

Had finished initialization, but how be used? We want the place that enters in the person that use only, the data that uses Session to store originally, like the account, record time, in changing us to build good Application boy or girl friend OK:

It is quotative content below:
‘ seeks the space that was not used
For I = 1 To Application(”ClientMax” )
If Application(”User_Status_ “&I) = 0 Then
The person that ‘ is used is temporary numberSession(”Index” ) = I
‘ lock is decided
Application Application.Lock
‘ is set into the position that already used
Application(”User_Status_ “&I) = 1 ‘ puts variable data
Application(”User_Account_ “&I) = Account
Application(”User_Logtime_ “&I) = Now()
‘ removes the lock is decided
Application.Unlock
Exit For
End If
Next

The relevant and variable data that should obtain the person that use resembles the practice below:

Response.Write(Application(”User_Account_ “&Session(”Index” ) )

You may discover, be to say not to use Session? Why does that still have the presence of Session in the primitive code above? Also had said in front, this replacement scheme can not replace Session completely, the browser is not in online condition with Server all the time, read take a page to break a string, how should we know then next time online be still same individual? Must want to rely on Session at that time, we give the person that use a group real time number, the person that this number is used namely the number at space of the variable on Application, you can imagine the safe that there is a lot of in the bank, you have a key, and there is number on the key, the number on the key can let clerk guide you to go yourself’s safe. This method still still has improvement place, but to diminutive application the program has been very enough used.

■ the 2nd plan

About on one plan, you also may think of, we used Session to record from the number that order, say number, session object has offer ” SessionID ” method. Right, no matter we want to be not used, server can help every user automatically write a number, and this number won’t repeat, use Session.SessionID to obtain namely as to this number. This writes a number is the motion that Session can make certainly, we can use it to replace the number program that ourselves writes, also saved a time again, have even bigger expanding. But basically, the first plan above or the use that have it are in, wait Xiaoying a moment to use a program like the chatting room that is meeting limitation number, next the 2nd replacement scheme, be aimed at larger system namely.

Number of the station on every second is amounted to hundreds thousands of very consummate the website of 10 thousand people, the plan before using, sure won’t do. Assume you set upper limit number 10000, server activations to be able to help you cut the person that 10 thousand area prepare to be used to 10 thousand, if has 5 variable in an area, a variable occupies 32 byte (Byte) , 10000 occupied 320000 K(320MB) above, server activationed to fill in so much rubbish arrives memory, efficiency certainly will still is done not have on battlefield is reduced many; And do not see these numbers very few, think oneself 512 MB can be used quite, the number above is hypothesis figure of a minimum, add Server can additional when configuring memory use unknown of how many resource, meet only so more won’t be lower. Because this solves method to have space of variable of the person that dynamic configuration is used only, should the ability when the person that use and Server are online cuts an area, must not want to had configured huge memory beforehand so.

It is simpler that the 2nd plan is done, ask the thing of a the first plan to desertion entirely, we do not need to move Global.asa, the place that needs to change the person that use to ascend only and other are useful the place that reach:

It is quotative content below:
The lock decides ApplicationApplication.Lock ‘ to put variable data
Application(”User_Account_ “&Session.sessionID) = Account
Application(”User_Logtime_ “&Session.sessionID) = Now() ‘ removes the lock decides Application.Unlock

The relevant and variable data that should obtain the person that use resembles the practice below:

Response.Write(Application(”User_Account_ “&Session.sessionID) )

Read a lot of books before, what writing Session to eat resource is very fierce, do not want to use as far as possible, can be when must be being used, still must use, more appropriate settlement did not teach method again in the book. Understood how to replace Session when you now, go using well! The efficiency problem that often puzzles probably can be improved accordingly many!

Bookmark:Digg Del.icio.us Reddit

Leave a Comment