Click here to Skip to main content
0 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


43 bookmarked
Posted 29 Jan 2000
Licenced CPOL

Calling scripts within scripts

, 29 Jan 2000
Rate this:
Please Sign up or sign in to vote.
A Component for calling a URL from an ASP script and reading back the output
  • Download source files - 27.5 Kb
  • Overview

    When writing an ASP script, it is sometimes useful to temporarily transfer execution to another script, and then continue the original script with the result of the called script.

    This is what the AspRetrieve component does. You can think of it like calling a procedure.

    The AspRetrieve component acts similar to the new function Server.Execute in IIS 5.0. In addition, you can pass parameters, either by GET or by POST.

    The functionality of the AspRetrieve component in brief:

    • call any URL from within an ASP script
    • pass parameters to the URL either in the URL itself (i.e. by GET) or by POST
    • retrieve the results form the called URL as a string

    Because I only needed limited functionality, only textual results are correctly returned from the called URL. i.e. you can call a HTML page, or an ASP script, but you cannot call a GIF or JPEG image, since the latter two return binary data.

    If you would like to extend the functionality, I would love to have this new version.


    The AspRetrieve component consists of two parts:

    • A MFC/ATL component that uses the Wininet functions to call an URL
    • Some ASP functions that aid in accessing the MFC component

    In addition I included some examples


    • Compile the MFC/ATL part of the component, using Visual C++ (I used the german version of Visual C++ 6, SP3)
    • Copy the component to whatever directory you want it, ensuring the account under which IIS runs (IUSR_XXX) has the correct permissions to access the component
    • Register the compiled component using regsvr32 (which is in your windows' system directory). Just type regsvr32 aspretrieve.dll at the command prompt
    • Copy the ASP function file to whatever directory you want
    • Include in your projects and begin using it


    When everything is installed correctly, just include the file in your ASP scripts and call the two functions Retrieve(url) and RetrievePost(url,params). You can either use relative URLs or absolute URLs for calling.

    A practical use of the component is at those places, where you would need a lot of Response.Write statements to produce HTML output. Those functions can now be separated into extra ASP files, feeded with parameters and called via the AspRetrieve component.


    Imagine you have a function that creates a table by code. 

    Without the AspRetrieve component, you would write something like this to implement the function:

    sub makeTable( byval cols, byval rows )
    	dim c,r
    	Response.Write "<table border=""0"" width=""100%"">"
    	' create rows.
    	for r=1 to rows
    		Response.Write "<tr>"
    		' create cols.
    		for c=1 to cols
    			Response.Write "<td width=""100%""></td>"
    		Response.Write "</tr>"
    	Response.Write "</table>"
    end sub

    You call the function like this:

    <% makeTable 10, 20 %>

    When using the AspRetrieve, you implement the function in a separate ASP script like this:

    <table border="1" width="100%">
    	' create rows.
    	dim c,r
    	for r=1 to Request("rows")
    			' create cols.
    			for c=1 to Request("cols")
    				<td width="100%"></td>

    You could then write a wrapper to simplify calling:

    sub makeTable( byval cols, byval rows )
    	Response.Write Retrieve( "maketable.asp?cols="&cols&"&rows="&rows )
    end sub

    And finally you would call the wrapper in your code

    <% makeTable 10, 20 %>


    The advantages of using AspRetrieve are that you can divide a complex application into individual modules. You can create a library of ASP scripts that you can call as needed. 

    In addition by cutting down the number of times you need to use Response.Write, you simplify your code. Having code in separate files, you can even use a graphical layout tool to modify your files, which is impossible if you construct your page with Response.Write.

    Another benefit is that you no longer need to include all files "at compile-time" using the <!--#include--> directive, but can "include" these files dynamically at runtime using the Retrieve function! (a feature that e.g. JSP has by default).

    Please feel free to ask any questions you have by e-mail:


    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


    About the Author

    Uwe Keim
    Chief Technology Officer Zeta Producer Desktop CMS
    Germany Germany
    Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

    In his free time, he does climbing, running and mountain biking. Recently he became a father of a cute boy.

    Some cool, free software from us:

    Deutschsprachiges Forum zu Elektromobilität und Tesla  
    Windows 10 Ereignisanzeige  
    German Developer Community  
    Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
    Homepage erstellen - Intuitive, very easy to use. Download now!  
    Send large Files online for free by Email

    You may also be interested in...

    Comments and Discussions

    General"Print & Go" script with Uwe's help Pin
    Juliansongs6-May-04 23:34
    memberJuliansongs6-May-04 23:34 
    QuestionHave you guys tried this? Pin
    Christian Calderon15-Feb-04 16:32
    memberChristian Calderon15-Feb-04 16:32 
    AnswerRe: Have you guys tried this? Pin
    Uwe Keim15-Feb-04 19:49
    sitebuilderUwe Keim15-Feb-04 19:49 
    Generalaspretrieve.dll in asp .net Pin
    haninaya2-Dec-03 3:38
    memberhaninaya2-Dec-03 3:38 
    QuestionHow to through proxy? Pin
    tonyjun15-Oct-02 22:30
    membertonyjun15-Oct-02 22:30 
    QuestionHow to get AspRetrieve? Pin
    Anonymous19-Sep-02 23:48
    memberAnonymous19-Sep-02 23:48 
    AnswerRe: How to get AspRetrieve? Pin
    Uwe Keim19-Sep-02 23:58
    sitebuilderUwe Keim19-Sep-02 23:58 
    GeneralRe: How to get AspRetrieve? Pin
    Anonymous20-Sep-02 0:06
    memberAnonymous20-Sep-02 0:06 
    GeneralHey ,Uwe.I use your component,some error occured. Pin
    Anonymous20-Sep-02 0:29
    memberAnonymous20-Sep-02 0:29 
    GeneralConfirmation of Previous Message Pin
    Member 3465876-Aug-02 19:42
    memberMember 3465876-Aug-02 19:42 
    GeneralRe: Confirmation of Previous Message Pin
    Uwe Keim19-Sep-02 23:59
    sitebuilderUwe Keim19-Sep-02 23:59 
    QuestionIs WinInet really suitable for this ?? Pin
    20-Jun-01 4:10
    suss20-Jun-01 4:10 
    QuestionCan someone send me a compiled dll Pin
    Alan Warchuck8-Mar-01 10:21
    memberAlan Warchuck8-Mar-01 10:21 
    QuestionNew session? Pin
    25-Jan-01 0:01
    suss25-Jan-01 0:01 
    Questionbug? Pin
    Andre Milton18-Jan-01 20:52
    memberAndre Milton18-Jan-01 20:52 
    AnswerRe: bug? Pin
    Uwe Keim18-Jan-01 20:54
    sitebuilderUwe Keim18-Jan-01 20:54 
    GeneralRe: bug? Pin
    Andre Milton18-Jan-01 21:02
    memberAndre Milton18-Jan-01 21:02 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
    Web01 | 2.8.190419.4 | Last Updated 30 Jan 2000
    Article Copyright 2000 by Uwe Keim
    Everything else Copyright © CodeProject, 1999-2019
    Layout: fixed | fluid