ASP page production in .NET Framework environment

zhaozj2021-02-08  227

Network company layoff, website close, electronic reports ... After the e-commerce retardation, some people have begun to question e-commerce. Perhaps the Internet is no longer weaving the dream of making big money, but after years of baptism, the Internet has become a part of the mass life. It is said that the country of the country in Taipei can make the webpage is quite common, which is visible. One spot, when the web is made into general knowledge, I want to survive on the Internet, enough, enough, professional will be a winning factor.

Under the .NET Framework, the author is gratifying ASP (Active Server Pages) to become more professionally, simply reviewing the past ASP, we can at least point to several disadvantages:

You can only develop ASP using the two programming languages ​​of VB Script or Java Script. There is no good detection (Debugger). The web structure will become chaos along with the program. ADO cannot be combined directly with the DataGrid component.

The author will explain the new look of ASP (Microsoft refer to this new ASP as ASP.NET).

From ASP to ASP.NET

ASP will become very red, I am afraid that Microsoft also feels unexpected, because ASP has always been attached to IIS, can't count independent products. The correspondence with the IIS version and the ASP version is as follows:

IIS version comes with ASP version IIS 3.0ASP 1.0IIS 4.0ASP 2.0IIS 5.0ASP 3.0 under IIS

Some people will use 1.0, 2.0, 3.0 to distinguish the version of the ASP, but the author does not agree, because from the ASP version 1.0 to version 3.0 version, Microsoft does not spend too much to improve the ASP, just because IIS revised, So ASP is also tiny The revision, so from the ASP version 1.0 to version 3.0, there is no significant change in function, so the author calls them ASP regardless of the ASP 1.0, 2.0 or 3.0.

With more and more users of ASP, I hope ASP better voice is also more strong, maybe it is as good as flow, perhaps to promote .NET Framework, Microsoft has made market surveys against ASP users, to find ASP must The improved place, and the next generation ASP is developed, which is ASP.NET (or asp ).

ASP.NET compatibility with ASP

Upgrading from ASP to ASP.NET, everyone is the most worryable problem may be "Will not affect the operation of both ASP pages", the author upgraded the ASP job platform to the ASP.NET job platform (this article writes the ASP installed when writing. The NET version is beta 1), and has not found existing ASP web pages that cannot work or must be modified.

In actual operation, when the ASP page (with .asp is the secondary file name), IIS will start asp.dll to execute the ASP page, and when the ASP.NET web page (with .aspx is the secondary file name) IIS will start xspwp.exe to execute the ASP.NET web page. After the execution files of the two are not just installing the ASP.NET, it will not affect the operation of both ASP webpages, actually ASP web pages and ASP.NET web pages. It is coexisting.

Another common question is: Do you need to convert an existing ASP page to an ASP.NET web page? Since the ASP page and the ASP.NET web page is coexisting, the ASP web page operated smoothly can be temporarily unable to modify. As for which web pages must be ASP.NET? The following is the author's suggestion:

Hopefully when the effect is higher: When the ASP.NET page is first browsed, Server will first compile them into MSIL (Microsoft Intermediate Language), and store it, and it is no longer recompiled (unless. The content of the ASPX file has changed), so it can be improved. In addition, the ASP.NET also has a web page and a data cache feature (see later), which can also enhance the response speed of the web page. We need frequent maintenance or modification: Since the ASP.NET uses VB7 as a program language, a complete object-oriented feature helps web page maintenance. Future new development page: Since the ASP.NET function is better than ASP, the future developed web page is of course ASP.NET. Change of program language

From the ASP to ASP.NET, where the changes are quite, but the most personal relationship with the ASP webpage maker should be the change in the program, and the ASP only accepts two programming languages ​​of VB Script and Java Script, but for ASP.NET. It is said that you can compile into MSIL-based languages, all program languages ​​acceptable by ASP.NET.

The author introduces MSIL in the ".NET Framework - Microsoft New Generation Software Development Environment" in the first 3 of the Run! PC, it is a mediation language that is between high-order programs (such as VB) and machine code. Language, under ASP.NET, our programming language will also be compiled into MSIL, then MSIL is compiled into a machine code, the process is as shown in Figure -1, ASP.NET also uses this mode, except for the output Outside of the browser, the ASP.NET web page is the same as the working mode of other program languages.

Figure -1 ASP.NET web page compilation process

Performance

The first time you contact the ASP.NET web page may have such questions: "Do you seem to be as if it is not as good as ASP web page?", About this problem, let the author talk to the operation mode, first see Figure-2, you can see The ASP.NET web page is more compiled more than the ASP page.

Figure -2 Comparison of ASP and ASP.NET Operation Mode

Although the ASP.NET is compiled more than the ASP page, this does not mean that the performance efficiency of the ASP.NET is more time, referring to Figure-2, the compilation execution speed of the ASP.NET phase 2 is superior to the ASP, but ASP.NET The compilation speed of the stage is slower than the ASP, simply, the time of the ASP.NET phase and the time> ASP execution time.

If viewed from the above comparison, ASP.NET is indeed more slow than ASP, but please share the browsing of the web into the following: (1) The page is first browsing (2) The page is browsed second time, as shown -3, when the ASP.NET page is first browsed, it will pass through two phases, so the speed is slower, but after the first browsing, MSIL will be stored, so when the same page is browsed second time. It is only necessary to compile the time from MSIL to the machine code and then execute, the result is faster than the ASP page, the overall comparison is as follows: (> said faster)

ASP.NET web page for the second time browse> ASP page> ASP.NET web page first viewed

Figure -3 Differences in the first browsing and the second browsing

.NET Framework object category

Microsoft claims that .NET Framework has a lot of benefits, but the author is most important that the object category provided by .NET Framework has hundreds of items, including data, database, drawing, network, XML, execution, directory service, security ..., etc. In the past ASP webpage, although ActiveX objects can be used, it is only limited to ActiveX DLL in the ActiveX object, unlike general applications (such as VB program, C program) can simultaneously use a variety of ActiveX objects such as ActiveX DLL, ActiveX EXE, and ActiveX Components. However, this phenomenon has improved under the .NET Framework, in the item category provided by the .NET Framework, in addition to the item category (eg, WinForm and Console) related to the screen output, it is not available. Other item categories are available in the ASP.NET web page.

Note: WinForm contains Windows-related object categories, console is the object category of the DOS text output mode. For ASP.NET, it is marked as a browser, so it is not available to Windows Windows and DOS Text. Windows, ASP.NET dedicated output item categories are called WebForm, the Windows application is not available.

WebForm and Server control components

In ASP's web page production, if we want to design a input form (form), you can only use the HTML input field (or a control component), ASP.NET has made great strengthening in this regard, in its WebForm Inside, we can arrange a variety of control components (collectively referred to as the Server control component), including:

Server control element function CheckBox, CheckBoxList enhance the function the RadioButton HTML checkbox is, RadioButtonList reinforcing HTML select button function TextBox reinforcing HTML text input function ListBox blocks, DropDownList enhancements the Table HTML drop down menu, TableRow, TableCell reinforcing HTML table Functional Label Enhances HTML Text Features Image, ImageButton Enhances HTML Picture of LinkButton, HyperLink Enhances HTML Connection Function Panel Multiple Blocks ADROTOR Advertising Cancel Board Calendar Date Display and Select Information Verification Class Control Components Don't write the program, help us verify that the information entered by the user correct DataGrid, DataList, Repeater Database display

In addition to providing a richer control element, another advantage of WebForm can record the state of the web page. In the past, in the ASP page, to record the status of the Client side, you must use the session or cookie object, but no matter whether it is a session or cookie object, Both must be operated under the NST to open the browser, ASP.NET improves this phenomenon, as long as we place the Server control element in WebForm, WebForm will record the status of all Server control components (such as control) The text entered in the component).

Record the ability to control the status status, to be divided into a plurality of input forms, with the input form of Figure -4 as an example, if the design of the ASP is used, the information entered in step one and steps must be recorded in Session or cookie. In the article, the step three is read, but the ASP.NET web page, as long as the SERVER control element of step one, step two, step three is arranged in the same WebForm, or no matter which step is executed, you can read Take the information entered in the server control element. Figure -4 is divided into a form that entered multiple times

ADO and data control components

The information inventory provided by .NET Framework is called ADO (Active Data Object ), although there are many ideas similar to ADO, but they are new objects, why there have been ADOs, but also provide ADO ? The author feels that there may be a few:

Using XML as a data exchange format: Since XML has become a standard for Internet exchange information, this is an unable to move. The range of extension: Under the ADO, any information must be accessed through OLD DB or ODBC, and ADO has no limit. Any program can make yourself a new information format with the object provided by ADO . Therefore, the range of accessible information is extended. Integration with data control components: When we write ASP web pages, the most inconvenient place is the display of the database content, in order to display the contents of the database, you must probably read the information record by means of ADO's Recordset object, and then The pen is displayed, the program is less lengthy, in the ASP.NET web page, we will arrange the DataGrid, DataList or Repeater, and then tied to ADO , and the DataGrid control components will automatically display the database. content. Referring to Figure -5 and Figure -6 is a web page that displays the data library content using the DataGrid and DataList control components.

Figure -5 http://www.kjedu.com.tw/kjaspx/ch01/ASPXPAGE.ASPX page

Figure -6 http://www.kjedu.com.tw/kjaspx/ch01/datalist.aspx

Cache and effectiveness

In order to improve the performance, the ASP.NET web page will be compiled into MSIL to save in the hard disk, and the next time the page is browsed again, you can directly execute the stored MSIL (details, please refer to "to perform performance "Description of the paragraph), in addition to this, the Cache (Complete Memory) functionality provided by ASP.NET can also improve the performance performance. The cache feature provided by ASP.NET is divided into Output Cache and Data Cache.

Output Cache and web page

Figure -7 Output Cache and web page

Referring to Figure-7, the so-called Output Cache, after executing MSIL, first write the result to Output Cache, then remove the Output Cache to the browser, and if you browse the same web page, ASP.NET will first determine if the page is There is Output Cache existent, if there is, then the Output Cache is directly to the browser, and the performance can be improved by compiling .aspx and executing MSIL.

To enable Output Cache, it is very simple, as long as the top of the .aspx web page, the following name is added:

<% @ Outputcache duration = "second number"%>

Where Duration indicates that Output Cache is retained in the system, for example: <% @ outputcache duration = "10"%>

The output cache of the page will remain in the system for 10 seconds, and anything to browse this page within 10 seconds, ASP.NET will directly pass Output Cache to the browser, omit the compilation action.

Data Cache and data

In addition to storeing the entire web page outside Output Cache, we can also store local data to Data Cache (hereinafter referred to as cache). The use of Cache is similar to the Application object, for example:

'Store information or objects in Application object ("Key1") = "This is a string" Application ("key2") = obj' stores information or objects in Data Cache ("Key1") = " Is a string "cache (" key2 ") = OBJ

However, the author must explain that the memory occupied by Data Cache may be released at any time (depending on the case where the system memory is used), so whenever we want to read the Data Cache, you must first judge whether Cache ("key") is Is equal to Nothing, if it is not equal to Nothing, indicating that Cache ("key") is still in the system, and can read.

Provision of detection

In the process of writing, it is inevitable that there will be errors, how to deactivate any programming designer, is very important and unavoidable. The ASP's detection tool is very lacking. In order to improve this deletion, ASP.NET provides the following method:

Set the CustomerRors section Using Tracking (TRACE) Function Default Tools (Debugger)

Set the Customerror section of Config.Web

When a web page generates an error and cannot be further compiled or executed, the ASP.NET will display the picture of Figure -8. This screen only tells us that the program is wrong, and which line is not displayed. In order to make ASP.NET display further error messages, add the setting of the Customerror section in the Config.Web file, as follows:

After browsing, you can see a more detailed error indication screen (as shown in Figure -9)

Figure -8 ASP.NET web page compiles or performs error screens (图))

Figure -9 ASP.NET web page compiles or performs errors (error messages more detailed) (Figure 5)

Use Trace Tracking

The so-called TRACE function is to add the following indications on the top of the web page:

<% @ Page Trace = "True"%>

After the page is browsing, additional information will be added, as shown in Figure -10, and these information helps our development of the status, as a reference.

Figure -10 TRACE function enabled the web page (图 略)

In the picture-10 screen, additional information can be divided into the following segments in addition to the content displayed by the web page:

Request Details: The information read to the browser through the request. Trace Information: The process of event or program execution. Control Tree: The relationship between the control elements and control elements used by the web page. Cookies Collection: Cookies used by the web page. Headers Collection: The header of the browser. Server variables: Server variables, that is, we can read through Request. ServerVariables (). In addition to let ASP.NET automatically display the above information, we can also display data in the TRACE INFORMATION segment in the TRACE.WRITE or TRACE.WARN, such as

Trace.write ("UploadFile ()", "Enter UPLOADFILE Event Programs" trace.warn ("UploadFile ()", "Enter for Back")

As a result, the message can be output to the Trace Information section for our reference.

Defractive Tool Program (Debugger)

The Debugger program provided by ASP.NET is very like VB's operating interface, which allows us to set the interrupt point, step-by-step execution, observe variables, and stack ..., is the discontactor. Before using Debugger, you must add the following settings in the config.Web file:

Next, start the C: / Program Files / Microsoft.Net / FrameworkSDK / Guidebug directory, then use the following steps to detect .aspx webpage:

1. Select "Debug -> Processes" of the DBGurt.exe menu, when you appear "Processes" Talking window, check "Show System Processes" and "Show Processes in All Sessions", then in the "Available Processes" field The bottom is found to find xspwp.exe (Note: If xspwp.exe is not seen, start the browser to browse any .aspx webpage, then press the "Refresh" button), after selecting, press the "attach" button, process Figure -11.

Figure -11 DBGurt.exe's "Process" conversation window (图 略)

2. The "Attach to Process" conversation window will appear (as shown in Figure -12), press the "OK" button.

Figure -12 Attach to Process Talking Window (Figure)

3. Next, return to the "Processes" conversation window of step 1, press the "close" button.

4. Select the "File -> Open -> File" of the DBGURT.EXE metrics to select the .aspx file you want to detect, here you can choose a plurality of files that you want to detect.

Development of objects

Since ASP.NET is a program language in VB7, all of the object-oriented functions of VB7 can also be played in the ASP.NET web page production, and in addition to the object-oriented features provided by the program language, ASP.NET can develop a webpage-specific Items - Pagelet (web gadget).

What is PageLet (web accessory)? From the example in life, when we decorate the Christmas tree, often buy some gadgets, then place them in the location, the concept of Pagelet is also similar, some common accessories, we can design them Pagelet, let other pages to use, give a more practical example, such as laying a Label control component and a TextBox control component in our web page, which is inserted into a Label type Pagelet and a TextBox type Pagelet in the web page. This article lets the author first show a simple Pagelet, this Pagelet is named Footer.ascx, as follows: (Note: Pagelet must be .ascx as the secondary file name)


learn Visual Basic to find kingdom

Check the contents of Footer.ascx, you will find that only HTML indicates, completely without ASP.NET, such .ascx files can also form PageLet? The answer is yes, the simplest Pagelet is only HTML-labeled .ascx file, let's take a look at the page using this pagelet.aspx:

<% @ Register tagprefix = "kj" tagname = "footer" src = "footer.ascx"%>

Using the easiest Pagelet - Usefoot.aspx
Viewing the contents of Footer.ascx, you will find that only HTML indicates, completely without ASP program, can such a .ascx file constitutes Pagelet? The answer is yes, the simplest Pagelet is only the .ascx file that only HTML is marked.

The result of the web browsing is shown in Figure -13.

Figure -13 Usefoot.aspx

In addition to only HTML indicates the simplest Pagelet, the Pagelet may also contain attributes and methods, and for Pagelet containing attributes and methods, the usage is identical to the Server control element. When we think that the Server control components provided by .NET Framework are not enough, you can use our own Server control components using the function of making Pagelet.

Web Services

Unlike ASP webpages, you can only access the native database, ASP.NET provides Web Services feature to allow us to across internet access resources. In the VB6 era, Microsoft issued RDS (Remote Data Service), you can also allow us to access another server database on the Internet, but there are still two shortcomings: (1) General users are not easy (2) Unable to cross the platform: Use RDS across internet access databases, regardless of the server-side or Client end, you must use a Windows job system. Web Services improved the shortcomings of RDS, in addition to become more easy to get started, Web Services use XML as data transfer format, making data to cross the platform, and more importantly, the ASP.NET web page can also be enjoyed This service can also be provided.

In the job mode, let the author give an instance to explain, see Figure-14, assume that the browser will access the Server A web page, but Server A's database comes from Serverx, then Server X is to provide an access database. Web Service, on the other hand, Server A, to establish a web database agent, and then exchange the SERVICE data exchange (using XML format) through the Web Database Agent (using XML format), and then achieve the purpose of accessing the Server X database.

Figure -14 Access Web Database (Subrigital Library across internet access)

Conclusion

Perhaps the e-commerce has been overestimated over the past two or three years, but web production technology has become a must-have knowledge of the information. Although Since Microsoft published IIS, ASP has been underestimated, so it is just IIS's accessories, now I am very happy ASP.NET is finally independent from IIS, and the function is related to VB, C # ... equation language, believe in the future ASP Web production will enter another new century.

转载请注明原文地址:https://www.9cbs.com/read-3115.html

New Post(0)