Asp. NET CCP Code

Source: Internet
Author: User
Tags constant odbc split fast web visual studio
asp.net in asp.net because of the direct use or conversion of DLL files, most people do not care about the problem of sharing the original password, since ASP.net is able to edit the latest original code to perform the Web site, it is necessary to use a DLL to run the web. There is no absolute norm for the manager, But for a system or a programmer, the same source code means that the same original codes are available for each project to share, when you develop or maintain a specific case, the change to the common source code is also equivalent to updating all the cases together, and it also reduces the same functionality like the original development maintenance time, It is helpful for the promotion of the development and the development of the small group of professionals.

For example, an early dedicated access library might have been developed with OLE DB, and after the. Net Framework 1.1 was taken into ODBC, when a new program was developed, ODBC support was added to the common code, and the original case was also supported by ODBC.

There are three ways to share the original code in the asp.net:

Using Web User Control (*.ascx)
Declaring a block with a code
Server-side include instruction notation
Most of the Web user control is introduced in the online manual or related asp.net, so this article does not repeat the introduction, and Methods 2, Method 3 can be a very small amount of information, can refer to the end of the other reference information listed in the site. In the above approach, WEB user control is part of user interface sharing, and code area or Include directives are common in languages such as class, modular, or HTML, and vary in use and classification.

First, set up a test sample, cut the original code into four file parts, as shown in Figure 1, which is as follows:


Chart 1
Test.aspx

<%@ Page language= "vb" autoeventwireup= "false"%>
<script language=vb runat=server src= "Testclass.vb"/%>
<!--#include virtual = "include.aspx"--%>

Testclass.vb

Public Class TestClass
Public Function Test () as String
Return TypeName (Me) & ": Testclass.vb Function"
End Function
End Class

Include.aspx

<script language=vb runat=server src= "Testfun.vb"/>
<script language=vb runat=server id= "Modinclude" >
Function Test1 ()
Response.Write (TypeName (Me) & ": Include.aspx Function Test1" & "<br>")
End Function
</script>
<%
Dim CTest as New TestClass

Test1 ()
Test2 ()
Response.Write (Ctest.test () & "<br>" & vbNewLine)
%>

Testfun.vb

Public Function Test2 ()
Response.Write (TypeName (Me) & ": Testfun.vb Function Test2" & "<br>")
End Function

Test.aspx is an actual web page, and the other three files are an example of a shared introduction, and there are two ways to introduce an external source:

Declaring a block with a code
<script language= "Codelanguage" runat= "Server" src= "pathname"/>
In this area, you can create objects, columns, and so on, and share the original codes with Visual Basic. Net, such as Testclass.vb in this example. It is not possible to create new modules within the Web Form, so if Testfun.vb cannot use Module ... End Module. In the object category, because of its contents, it is not possible to have any of the original codes directly in the file, to use the Visual Studio. Net IDE Environment (the following is simple VS. NET) to edit the source code, it is recommended to use the password to declare the area as the main object, to avoid vs.net hint errors.

Server-side Include instruction notation
<!--#include File | Virtual = filename-->
This approach, as the original ASP introduced the file, due to a part of the ASPX original file, so in the file can be used in the Web Part of the relevant settings, but also the introduction of other original codes. To use the Vs.net edit source code, the suggested file name is. aspx, which allows you to use Vs.net to prompt for error, self awareness, and connectivity.

In the test case, to ensure that the original code was introduced in motion, do not use the functions performed in the vs.net to create DLL references according to the application to make it difficult to tell whether the function or object functionality is introduced by the original code, so please direct it by Internet Explorer (hereinafter IE) The URL is entered directly into the Http://localhost/Include/test.aspx Web site. Moreover, since it has not been translated through vs.net, therefore, if you use vs.net to create this example, manually remove the Inherits from the Global.asax and every Web Form (*.aspx) in the original code, so that you do not have to ask Problem

In this example, the code separating the main contents of the Web page is placed inside the include.aspx, and call each function or create an object, on IE, showing the results as shown in Figure 2, a simple motion to share the original code in this form, if each part of the password has been modified, as long as the reorganization of IE, You can display the Web page in the revised code, and you'll get a little flexibility in your web system maintenance and your expertise.


Chart 2
A step further
You might want to share the variables or functions in other parts of your content, and you'll find that you can't use them directly in the inside, and there are three ways to use them:

Declaring variables or functions with the Shared key
Transfer the main object as a variable
Declaring a main object reference
By adding shared.aspx to the original example, the test.aspx is also slightly modified to test, modifying part of the code plus the bottom line. The results of the modified code are shown in Figure 3.

Test.aspx

<%@ Page language= "vb" autoeventwireup= "false" Classname= "MyTest"%>
<script language=vb runat=server src= "Testclass.vb"/>
<!--#include virtual = "shared.aspx"-->
<!--#include virtual = "include.aspx"-->

Shared.aspx

<script language=vb runat=server id= "modshared" >
Public Shared Shdme as Object
Public Shared shdstring as String = ""

Public Class Ctestobj
Public Function Test (Byval commonobj as Object)
Return Commonobj.publicfun (Sharedfun ("Ctestobj"))
End Function
End Class

Public Class Ctestshd
Public Function Test ()
Return Shdme.publicfun (Sharedfun ("ctestshd"))
End Function
End Class

Public Class Ctestname
Public Function Test ()
Dim webtest as New myTest
Return Webtest.publicfun (Sharedfun ("Ctestname"))
End Function
End Class

Public Function Publicfun (Byval stroutput as String)
Shdstring &= "-[public]"
Return Stroutput & "-[public]"
End Function

Public Shared Function Sharedfun (Byval addstring as String)
Shdstring &= addstring & "-[shared]"
Return addstring & "-[shared]"
End Function
</script>
<%
Shdme = Me
Dim Clsobj as New ctestobj
Response.Write (Clsobj.test (Me) & "<br>")
Dim clsshd as New ctestshd
Response.Write (Clsshd.test () & "<br>")
Dim Clsname as New ctestname
Response.Write (Clsname.test () & "<br>")
Response.Write (TypeName (Shdme) & "," & shdstring & "<br>")
%>


Chart 3
Declaring with the Shared key
When a variable or function is declared shared as a common word, the variables and functions become more global, in this case, we declare that we share an object variable, a string variable, and a function, and since the change is a meditation variable, it can be stacked before all the segments of the session are connected. So the string variable declares the same initial value to avoid overlapping, but it does not necessarily need to use the Session object if there is a need for a similar variable to be used in the web system. Shared functions can be used directly in objects without considering the problem of naming space.

Transfer the main object as a variable
A passing object can be passed through an argument or using the shared variables mentioned above, in Ctestobj, the object is passed to the object in the form of an argument, and the ctestshd is passed through the shared variables. Since the Publicfun function is a common function under the main object, it has to be called through the main object naming space.

Declaring a main object reference
In Ctestname, the demonstration declares the use of a main object, which produces a disturbance, and what is the name of the main object? All the code in this article is introduced by test.aspx, and for ASP.net, it's actually just an aspx file, so there can only be one on the object name set, which is test.aspx. In the test.aspx modification case, by adding the ClassName of the first line, the specified name can be used in the Ctestname category, and if you do not specify a name, it is designed to replace the decimal point (dot) with that Web Form name as the lower minus (under Line) and then the name of the preset object, as in Figure 2, test_aspx is the object name, and in Figure 3 it shows myTest as the object name. Of course, it can be declared as a Test_aspx object in Ctestname, but it is often possible to make an object name more convenient in this case because of the common reason and not knowing which Web Form to reference.

Other features, in shared.aspx and include.aspx, there is a Code translation area (<% ...%>) that can also be used to specify a code or announce a specific variable in a separate, shared file, or in a different separation. For example, in a data library access code, you can split a string or a constant into a single source file, the code for the link is split into another source file, and different applications or different repositories can still refer to a shared code access repository, as long as they are able to separate the corresponding string declarations.

In addition, the variables after the shared announcement are shared in the meditation, in the same environment where multiple users are logged in, you can also consider shared variable exchange messages, such as the constant accumulation of text strings in a chat room, to use the shared variable to achieve the effect.

The last thing to test is the restriction of the dynamic common source code. When you use the code to declare the area, the reference depth is just one layer, since there is no way to refer to another code in this area. When using the include directive, the following profile can continue to use the include designator, so the maximum available depth is not known. In general, the depth test is a serial test, the test is a test, and usually the depth limit is more severe than the limit (the depth of the degree), so only the maximum depth test is done. First, the program outputs the following code to a different file, and n is tested in depth from 1 ~ 10,000. To make sure that each file is executed, you use the code translation area to perform the output function of the file in each file, and the threaded structure is shown in Figure 4.

Loop[nnnnn].aspx

<script LANGUAGE=VB runat=server>
Public Function responseloop[nnnnn] ()
Response.Write ("loop[nnnnn]<br>")
End Function
</script>
<% responseloop[nnnnn] ()%>
<!--#include virtual = "loop[nnnnn+1].aspx"-->


Chart 4
Test computer system for Windows XP SP2, equipped with P4 1.6g/384 MB, in the test computer, n between 4,650 ~ 4,800, but with a large number of references, the memory is very much consumed during the motion translation, and during the test n=4,650, the amount of memory used in the translation period is increased. 460 MB or so (aspnet_wp.exe), with other programs in the original drive using the memory of MB, reached the test computer memory limit, or perhaps in a higher level of the computer, can be a little further expansion depth. This memory has not reached the upper limit during the test n=4,800, that is, out of the error of image 5, and the ASP.net service program (aspnet_wp.exe) will always end up, and the error message is written into the event book to reactivate the ASP.net service program, so it can be presumed in the ASP. NET 1.1, the maximum depth is not exceeding 4,800.


Diagram 5 (in the picture) is a human-masked text string that is the name of the computer computer. )
More than 10 of the original, for the average person thinking about logical ability is a higher challenge, general programming also does not increase the depth unlimited, most of the depth is still 10, so the maximum depth over 4,650, for most of the management and maintenance, is far over the design requirements.

This article discusses the dynamic sharing of the original code can provide another direction for the medium and large system design and management maintenance, which can be considered as the master of the Web system design, at the time of the release or conclusion, the original code or DLL is delivered in accordance with the requirements of the contract, and in the case of multiple systems sharing the original codes, the cost of the original code can be reduced To enhance the power of the source management and maintenance, the library or function library created by the individual or the development group can use this method to manage the maintenance and reach the goal of a fast web system.



Related Article

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.