Programmer's topic
Next we will talk about how developers can quickly start ASP. NET programming.
You find that ASP. NET is more attractive than ASP?
Some people say it is configuration. Is it easier to configure ASP. NET? So I want to talk about this. We did find that one of the advantages of ASP. NET is that it can be easily configured. Because ASP. NET applications are composed of compiled code, you do not need to register a DLL or stop some services. For example, in today's ASP environment, if a very important commercial component on your website needs to be replaced by a more powerful component, you will have to suspend the WEB site service so that the DLL is not locked. Then, replace the component, register it in the system, and restart your WEB site. The result is that your site will not work externally for a certain period of time. However, the exciting thing is that in ASP. NET, you don't need to do any of the above work, and you don't need to consider the damn regsrv32. You only need to put the new DLL in the directory with the old DLL system. The new DLL request is still working, and the new request will trigger the new DLL, which will continue until the old DLL completes all the requests. At that time, the new DLL will replace the old DLL, which will not lead to downtime, all of which only need to call the XCOPY configuration function, which makes our work more efficient and more concise.
The advantage of this is that you do not need to consider which DLL needs to be closed, and then close it. Which DLL has a BUG. Is there a way to quickly disable all the DLL files of the current application, or you must stop the WEB site.
For me, it is easy to keep the previous version. You only need to reconfigure XCOPY, and those DLL will be replaced by yourself soon.
Well, in addition to the simple configuration feature, what advantages do you have to attract asp programmers to quickly transplant to the ASP. NET environment?
This is a good question. If I am a VB programmer, when I enter the ASP programming environment, I will find that I am so familiar with it that I am happy to write the program there. I don't have to worry about those scripting languages, and I don't have to worry about the linear processing model from start to end.. NET uses the updated logical relationship, uses more new server components provided, and provides more functions than ASP programs.
Indeed, ASP. NET saves a lot of development time. You can develop DLL for ASP + page calls in the same environment and use it securely. However, for most developers, the biggest benefit comes from the caching function provided by them.
We all understand the importance of the caching function for standard web pages. The client's caching can quickly reproduce the page. The server-side caching stores some compiled code and improves the access speed.
Here is an example of caching, an online store that sells CD. On his homepage, you listed a series of products. Therefore, you use a database to store product information, price information, and type information. When ASP scripts access the database, there will inevitably be a time delay. However, when you use caching, some accessed information will remain in caching. When the request information is retrieved within caching, the page in caching is output as the original page. Therefore, you do not have to access the database to obtain data, because they are already in caching .. The NET Framework will always monitor pages in caching. If the database information on these pages changes, it will immediately update these pages. Therefore, you do not have to worry about getting the latest data. Through the caching setting function, you can also set the length of the caching time to specify the time during which the caching content is regularly updated. You can also cache page hits in caching. In short, through the caching technology, you actually provide users on your site with the possibility of quickly obtaining information. In essence, he actually directly obtains the generated HTML page, thus avoiding a series of page generation processes.
Caching will help website developers adjust website performance and quickly respond to customer requests.
Yes. In fact, you can see that the website server can have more clicks every second, because most of your requests are in caching.
From the developer's point of view, what are the major difficulties they encounter when writing the first ASP. NET program?
I'm surprised to hear from you that there are no insurmountable obstacles from ASP to ASP. NET. They are different in some details. Of course, there are many things to be noticed. For example, we used to write programs using ASP and VB scripts. When we wanted to create a record set object, we had to SET a variable equal to the record set. ASP. NET does not have the SET parameter, which means that the variable is equal to the ADO records set object. Therefore, in ASP and ASP. NET only has some small syntax differences. These small syntax differences do not affect the page performance at all, but if you port ASP programs to ASP. NET, pay attention to these small differences. In fact, there is a small amount of code to migrate from ASP to ASP. NET, so you don't have to worry about porting the entire program code. The two can actually coexist. Therefore, you do not have to force your website program to be transplanted to ASP. NET immediately. You can gradually adopt the new ASP. NET Technology in your new work.
I think you can still declare all your data types as you did before. You can still use Server. CreateObject. You can still use dim rs to define a record set object. You can still use dim rs as new ado record set, right?
This is just one of our options. In our minimal porting level, you don't actually need to consider the differences between ASP and ASP. NET. You can still use dim rs to create data and related objects. The main difference between the two is that one is the object created with vb script, and the other is the object created with VB.
So now you have changed to a development language platform with a type of ownership?
You are right. We have data types. We are now more rigorous in application memory management, rather than regard everything as a variable, we can now regard different things as string, integer, a data set, therefore, we can better control the memory usage.
Next, we should demonstrate some code to explain the above.
Okay. Our first problem is transplantation. This is a typical ASP code page. We will retrieve data from the database and put it into the table. Let's take a look at the code. We first defined our connection and our record set. We created these objects. We SET our record set to execute connection with the set keyword. Next is a do while loop that displays information in the database on the page.
<%
Dim con, rs
Set con = Server. CreateObject ("ADODB. Connection ")
Con. Open "Provider = SQLOLEDB; server = (local); database = Northwind; UID = sa; PWD = ;"
Set rs = con. Execute ("SELECT ContactName, City FROM Customers ")
%>
<Html>
<Body>
<Table border = "0">
<Tr>
<Td> ContactName </td>
<Td> City </td>
</Tr>
<%
Do While Not rs. EOF
%>
<Tr>
<Td> <% = rs ("ContactName") %> </td>
<Td> <% = rs ("City") %> </td>
</Tr>
<%
Rs. MoveNext
Loop
%>
</Table>
</Body>
</Html>
To transfer to the. NET Framework, only a small amount of porting work is required. We can see what has been changed and what cannot be used. In Set con = Server. createObject ("ADODB. connection ") and Set rs = con. the set and other keywords used in Execute ("SELECT ContactName, City FROM MERs") are gone forever. However, in the following code, we add an attribute Value to the right of rs ("ContactName") and rs ("City. The basic meaning is that we can obtain the value of a specified row or column. From ASP to ASP. NET, there are actually few changes. You can see that ASP and ASP. NET code are almost the same, with no major changes.
<%
Dim con, rs
Con = Server. CreateObject ("ADODB. Connection ")
Con. Open ("Provider = SQLOLEDB; server = (local); database = Northwind; UID = sa; PWD = ;")
Rs = con. Execute ("SELECT ContactName, City FROM MERs ")
%>
<Html>
<Body>
<Table border = "0">
<Tr>
<Td> ContactName </td>
<Td> City </td>
</Tr>
<%
Do While Not rs. EOF
%>
<Tr>
<Td> <% = rs ("ContactName"). Value %> </td>
<Td> <% = rs ("City"). Value %> </td>
</Tr>
<%
Rs. MoveNext
Loop
%>
</Table>
</Body>
</Html>
This is very attractive. The SET keywords are removed, the VALUE keywords are introduced, and the Code itself does not actually change. Therefore, as long as you look at the output result, you will find that they are basically consistent. However, ASP. NET is running in. in the. NET Framework, the page extension is. ASPX, of course, we can also implement the CACHE function on this page, but it is not used in this program. If we further dive into the above instance and consider some more convenient means provided by the application. NET Framework and ASP. NET Framework. For example, if you use managed providers to obtain data, we will use the following example. We still work in the NorthWind database on SQL 7.0.
. NET provides an important means: SQL managed provide, which can be directly connected to SQL to obtain data without using OLEDB. This method has been recognized by practice to greatly improve the access speed. We can look at the following code in idea. They use pure VB instead of VBs. However, the output results are almost the same. What we need to do is import some namespaces and System. Data, so that we can have the most basic Data processing capabilities and obtain the SQL namespace that can access the SQL managed provider. The style of these codes is similar to the style of C # discussed earlier. At that time, we used C # to process the code based on. various class libraries of the NET architecture, which we have seen in VB. the. NET Class Library has the same style as the class library in C.
The two are indeed the same style. If I write code in C #, the code will be different, but the namespace is consistent. These two methods are good for compiling ASP. NET programs. Although some classes may be different, we can just modify a few places to quickly port the VB code into the C # code.
In fact, a lot of code will not be changed (keep it all the time ). For example, the SQL connection string only needs to be changed a little bit, S