In-depth study of session variable loss problem!

zhaozj2021-02-16  180

2001: 8: 13

Introduction: Many netizens have such questions recently, that is, when we set a session variable between a web page, to another web page, it disappeared. What is this reason? If you read this article in detail, I believe that I can give you a complete reply! One: Foreword - About Web Applications We today's web application is a platform for building a web application that is provided by Windows NT Option Pack. The web application can be delivered as a set of web pages, which provides a user interface to a database application that encapsulates transaction logic and provides access to stores important business information, and ActiveX components. That is, what we use the ASP program. When you create an application, you must use the Internet Services Manager to specify the application's start-up point directory in the Web site. Before discovering other startup points, each file and directory in a start-point directory in a Web site are considered part of the application. Therefore, the scope of the application can be defined using the directory boundary. ASP-based application is a collection of ASP pages and ActiveX components. When the user defines an application, use IIS to specify the directory of the application startup point in the user's Web site. Each file and folder in the user's Web site is considered part of the application until another start-up point directory is found. In this way, the user can use the directory as the boundary definition of the application's scope. Each Web site can have multiple applications, while each application has different configurations. Second: The scope of the web application is as mentioned above. We will set a web application, such as shopping programs, news programs, chat programs ..., etc., some of our developed ASP pages are set separately to become a web application. In conjunction with instances, as we will unify all the pages of a shopping program (such as registration page, shopping cart, cash register, order page, commodity page), collectively referred to as a web shopping program, its application range is from shopping Start all the pages involved in the end of the shopping. In IIS, the system must assign it into a virtual directory, and all pages of the virtual directory, and their subdirectories are the physical scope of their shopping programs. As shown in the following table. * Shop-index.asp -buy.asp catalog-list.asp Customer-a.asp -b.ASP $ *, representing a virtual directory, represents the subdirectory. Therefore, all the tops of the entire top form a web application. However, another application can be created in a virtual directory. As shown in the following table * shop-index.asp -buy.asp * book-book.asp catalog-list.asp Customer-a.asp -b.asp, INDEX.ASP, List.asp, A.ASP under Shop Wait for an application, and Book.asp under Book is not Shop, he is a new web application. Three: Web application range settings and applications If your development environment is Visual InterDev6.0, then the application settings almost don't need you to consider, everything has VI6 to set it up, and automatically establish in IIS The virtual directory, but if you are other, you may need to set him yourself in IIS. The specific steps are as follows: Create an application 1 - In the Internet Service Manager, select the directory as the application startup point.

You can specify the main directory of the web site as the startup point of the application. 2 - Open the property page of the directory, and then click the "Main Directory", "Virtual Directory" or Directory tab. 3 - In the Name text box, type the name for the application. 'Of course, the name of the application is not necessary. But recommended settings. 4 - Click the "Create" button. Since then, you can map your web application directory to this directory. Understand the above basic definitions, it is necessary for our network developers, it should be, it is because there is a range of web applications, it can make web applications to share information between applications, for example, ASP applications. Ambient flow, session status, and variable settings can be shared between its web pages. That is, the session, Application object, etc. we often use. It should be meaningful for only one application and its scope, Session, Application and other objects. IV: The session variable "loss" problem talks about so many concepts, it can finally say substantial issues, the session object is one of the most important portions in the web application, which is the existence of it, so that we can Transmit data across web pages, distinguishing different users. We can implement the variables to the session. This process is SESSION ("TEMP") = TEMP. But many netizens have such questions recently, that is, when we set a session variable between a web page, to another web page, it disappeared. What is this reason? Based on the concept, we can summarize the reasons, and treatment methods. 1: ASP web page crossing multiple web applications: This reason is that your web page may be another web application. Previously, some information emphasized the singleness of the session variable, as if a user is connected to a web host, it is only possible to create a session variable, which is wrong, the basis for the resolved session variable is the web mentioned above. Web Application range, instead of being created separately according to the user, you can try a piece below. Test.asp <% @ language = vbscript%> <% session ("temp") = "Temp" response.write session.SessionID 'sessionID is used to distinguish a separate customer in an application. %> Copy Test.asp to two different virtual directories, respectively. You can see that he is two different values. So, maybe your web page has span different applications. Of course, this situation may encounter such errors for beginners, that is, they themselves as a root directory, but when developing a virtual directory, set their subdirectory as a virtual directory. , Just like the second table structure mentioned above. So he also became two different web applications. It is not difficult to explain why it's wrong. 2: It may be a plurality of the same application. The first case is very good, it is easy to correct, but this second case is not easy to discover, it is also difficult to correct. Here we introduce another concept. Many of the same application coexist, (good, the key is Microsoft's concept, I forgot, this is my own. Oh!), It means that it is very well understood from this definition, which is for the same application. At the same time, you can exist in memory. As we are common with ACDSEE.exe, you can start multiple ACDSEE.exe by clicking.

And the other can not, we don't say its definition (if you say, it is the same application does not swim, huh,!) In the same time, if an application has been launched, you can no longer start the same application again. The app is. Such as foxmail.exe, when you start a foxmail.exe, it is likely to have a foxmail in memory. If you start, you will not open a foxmail window. And our IE belongs to the former, you can start multiple IE applications by clicking IE. At this point, we do another test below. You put the above code Test.asp in a virtual directory. Then, you click IE to start (note: By clicking IE, not pressing Ctrl N, nor by clicking the file, reopen a window) At this time, you can find that although they are the same address, the same address A user, but sessionid is different, of course, you can also build another file. Such as test2.asp <%> <% response.write session ("temp")%> At this time, you will find session ("temp") in another IE window, That is, we have just attached a value in Test.asp, and Test2.asp and Test.asp are lost in the same virtual directory, but Session ("TEMP" is lost. It turns out that relative to the same ASP application. Different IEs are relative but different ASP applications. (It's a bit like a winding, it is difficult to understand.) However, we have understood its cause, I believe it is not difficult to solve him. It is also important to note that we have mentioned repeatedly by clicking IE, not by pressing Ctrl N, nor by clicking the file in an IE window, reopening a window, here you want to explain if you pass in one The window opened by the IE window, which is a derived window, not a symbiotic window, that is, another window at this time belongs to the inheritance relationship with the previous window, which belongs to the same application range. 3: Improper connection is actually, the problem encountered by most netizens is to discover the session variables by clicking on the new window in the page. He is the same as the meaning of the new window of Ctrl N. But why is there a problem? Let's analyze its connection. It may be the same as Ctrl N, which is the same as Ctrl N, which is the same as Ctrl N, which may be the same as Ctrl N by


New Post(0)