How to write ASP into a DLL

zhaozj2021-02-08  205

This article mainly turns the ASP code into components, but also the speed of accelerating the ASP, but also protects your code.

Below, we will write a very simple component, focusing on how to develop DLL components, not their complex code! These must rely on yourself.

Server-side components

First, the server-side components must be different from the client's components. The client's components are transmitted over the network, relying on HTML to work. But only use it on IE. But the server side is running on the server side, which is executed on the server Various operations. Therefore, all browsers can be enjoyed, depending on the server instead of the browser.

When IIS is requested to execute an ASP program, it will first find the code between the <%%> tag in the ASP file, and execute it (or code between ). This ASP program is previously called, then it will return to the user with the compiled program in memory. If not, then it is recompiled. The ASP is more velocity than the CGI, because CGI is Each request uses a thread. This greatly consumed the resources of the server.

I don't want you to write the program you can run in IIS !! Now you will do it! Use VB5 (of course now VB6), you can build DynamiClinkedLibraries (DLL file), it can run directly on IIS (if there The ASP file is requested.

System and software requirements

You need a 32-bit operating system to run the ASP. Of course, you have to install IIS or PWS. We will develop under Windows95 PWS VB5.

let us start

Start your VB, select the ActiveX icon. This icon can be found in the new project! VB will provide a default engineering name (Project1) and class name (class1). We will change the two names. Before the rename First confirm that we have MicrosoftActiveServerPageSObjectLibrary, which is very useful in our programs. Select "Project" from the menu, then select "reference", will appear "Reference" windows

Select MicrosoftActiveServerPageSObjectLibrary from it.

Name your project and class

Now let's name it based on your hobbies! It is also important to name them. We will use this engineering name and class name to create instances of this component!

How to change your name, I don't want to say more!

Our engineering name is changed to Exmaple, named HelloWord

How to use engineering and classes

Now we have our own project (Example1) and class name (HelloWorld). We will use their names in the ASP code to reference this component. We reference this in ASP, as follows:

SetObjreference = Server.createObject ("Projectname.className)

Quote for our project is:

SetObjreference = Server.createObject ("eXample1.helloworld")

Now we can use Objreference to call our functions created in the component, subroutine. Below we will write a SayHello subroutine, we execute its code as follows:

<%

SetObjreference = Server.createObject ("eXample1.helloworld")

Objreference.SAYHELLO

%>

In order to use ASP methods in the HelloWord class, you must write an onStartPage in this class.

Sub function. As follows:

PublicSubonstartPage (PassedscriptingContextAsscriptingContext)

SetMyscriptingContext = PassedScriptingContext

EndSub

Now, whether the user visits an ASP file with this component, IIS will transfer ScriptingContext to our objects. This scriptingContext includes all ASP methods and properties. Implementation, this makes we have an ability to access Objects of all ASPs. Look at the following: PUBLICSBONSTARTPAGE (PassedscriptingContextAsscriptingContext)

SetMyscriptingContext = PassedScriptingContext

SetMyapplication = myscriptingContext.Application

SetMyRequest = myscriptingContext.Request

SetMyResponse = myscriptingContext.Response

SetMyServer = myscriptingContext.server

SetMySession = myscriptingContext.Session

EndSub

In the future, we can use MyApplication in VB to replace the Application in the ASP, which can replace Request, Server ..., but we come to declare these variables before onStartPage:

PrivateMyscriptingContextAsscriptingContext

PrivateMyApplicationAsApplication

PrivateMyRequestasRequest

PrivateMyResponseasResponse

PrivateMyServeras Server

PrivateMysessionAsSession

Objects using ASP

Our variables can now be used like a standard ASP object! For example, we often use request.form () in the ASP to collect data submitting forms. Now we implemented this function in our VB, the code is as follows:

Implement with ASP:

<%

Mytempvariable = Request.form ("UserName")

Response.write ("Yountered" & mytempvariable & "readyourusername")

%>

Implementation in VB:

Mytempvariable = myRequest.form ("UserName")

MyResponse.write ("Yountered" & mytempvariable & "askOOOOUSERNAME")

By using MyResponse instead of Response, we can use all response methods, of course, MyResponse name can be taken casually, you can even take Response.

Another thing we have to pay attention to, we have to write on our created class, this OnStartPage is the opposite! OnStartPage is an object, OneendPage is destroyed.

PublicsubonendPage ()

SetMyscriptingContext = Nothing

SetMyApplication = Nothing

SETMYREQUEST = Nothing

SetMyResponse = Nothing

SetMyServer = Nothing

SetMySession = Nothing

EndSub

Sayhello method

Let's create a sub-function to display "HolleWorld". This SayHello method is just a subfunction in the class of HelloWorld, and we will use the following display this method in the ASP.

<%

SetObjreference = Server.createObject ("eXample1.helloworld")

Objreference.SAYHELLO%>

Sayhello's program is very simple!

Publicsubsayhello ()

MyResponse.write ("HelloWorld")

EndSub

Now a small component is written, the rest is to compile this component, save it in the "Project" menu, what is the name, we use exmaple1.vbp! Then use "MakeExMaple1.dll in the menu" ", Compile it into a DLL file. A component is really completed!

Note that you have to turn off your PWS first, then compile this component. Otherwise, VB will tell you some components in use.

Use our own components in the ASP.

When you corrected the error in compilation, successfully compile the Example1 project, now you have to take out your favorite HTML editor to write down the following statement, save as an ASP file.

eXample1 </ title></p> <p></ HEAD></p> <p><Body></p> <p><%</p> <p>SetObjreference = Server.createObject ("eXample1.helloworld")</p> <p>Objreference.SAYHELLO</p> <p>%></p> <p></ Body></p> <p></ Html></p> <p>You can see the result after running:</p> <p>HelloWorld</p> <p>Registration component</p> <p>If you want to share your components with your friends, you have to register your components on your system. We generally use regsvr32.exe to register components. After registration, your components will appear in Win95 / Win98 In the Windows / System directory. Below is an example of registration:</p> <p>Regsvr32.exec: /wwwroot/example1/example1.dll</p> <p>In your system, VB will automatically register you, so you rarely use regsvr32.exe</p> <p>Here is just a very small component, you can write your bigger components, and you can use a lot of controls in VB.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-2512.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="2512" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.042</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '1sb1_2FUVr5HjZvkb1ZuqJuVlYJfFYp3V8f_2B4GKguEvVIZ_2FdInHpBpenHKqQ3DakuGWsRkSg258PNDEsFQJaUNhw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>