Print Page | Close Window

Call ASP page

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=12480
Printed Date: 30 March 2026 at 9:20pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Call ASP page
Posted By: Phat
Subject: Call ASP page
Date Posted: 09 November 2004 at 3:08am
Is there a way to run an asp page without actually displaying it?

I want to run a page form the global asa using Session_OnStart but i do not want the browser to be redirected there.

I just need the code to be run behind the scenes.???????




Replies:
Posted By: Mart
Date Posted: 09 November 2004 at 9:42am
hmm not the best solution but it works:

Response.Write "<div style=""display: none;"">"
Server.Execute "yourpage.asp"
Response.Write "</div>"


Posted By: dpyers
Date Posted: 09 November 2004 at 11:43am

Might also want to try...

Dim strRequestedPage
strRequestedPage = Request.ServerVariables("URL")
Sever.Execute "no_output_page.asp"
Server.Transfer strRequestedPage



-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: Mart
Date Posted: 09 November 2004 at 11:48am
Wouldn't that cause an eternal loop?


Posted By: dpyers
Date Posted: 09 November 2004 at 11:59am
Didn't think of that - It might - I haven't tested it. Off to do so now - lol

-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: dpyers
Date Posted: 09 November 2004 at 12:10pm
You are 100% right Mart. My answer won't work!
:-/

-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: Mart
Date Posted: 09 November 2004 at 12:18pm
I don't think theres a way to do it (apart from my "solution")


Posted By: dpyers
Date Posted: 09 November 2004 at 12:43pm
You can use a #include in global.asa, but it has to be external to the standard subroutines which means it gets run for all events.

-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: ljamal
Date Posted: 09 November 2004 at 1:25pm
It depends on what the ASP page is doing.
There might be other ways to accomplish the same goal.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: Phat
Date Posted: 09 November 2004 at 8:13pm
Well this is what i have been doing.  The problem is when i use it in global.asa it will not work. It gets a script timeout error. Which makes me think it is doing a loop forever.




If DateDiff("d", Application("LastScheduledRun"), Now()) > 0 Then

    ' Declare our vars
    Dim objWinHttp, strURL

    strURL = "http://address_and_page_to_call.asp"

    Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
    objWinHttp.Open "GET", strURL
    objWinHttp.Send


    If objWinHttp.Status <> 200 Then
        Err.Raise 1, "HttpRequester", "Invalid HTTP Response Code"
    End If

    Application.Lock
    Application("LastScheduledRun") = Now()
    Application.UnLock

End If




Posted By: dpyers
Date Posted: 09 November 2004 at 11:05pm

I assume you've tried to execute the code in a separate asp page successfully.

The only things I can think of are:

  1. Retrieval of the page is trying to write something out to the screen which is a no-no from global.asa.
  2. If an error is being raised, I think you'll need an On Error Resume Next in order to get as far as checking the objWinHttp.Status.
  3. The Application.Lock should be before the If and the Application.Unlock after the End If.
  4. When you change session stuff in global.asa, refreshing/restarting the browser usually creates the new session. When you change stuff in the Application level subroutines though, you have to restart the application to see any - or at least not strange - results. On some systems, running an asp script that contains <% application.abandon %> will restart the app (you have to shut down and then restart the browser after running the script).


-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: Phat
Date Posted: 10 November 2004 at 3:02am
dpyers your a champ.

One of the problems was one of the pages i was calling was using response.write so i got rid of that.

I was thought the same about the Application.Lock/Unlock as well so i updated it.

Seams to be working now. I will give it a couple off days to make sure though.

Cheers




Posted By: Phat
Date Posted: 11 November 2004 at 6:21am
back again. It still has issues.

I did the on error resume next but it doe snot return an error message. I have it sending an email when there is an error number but the email dope snot contain an info.

Also it runs more than once a day. Should an application variable hold for the period the server is running or does it reset each time the session starts again??



Posted By: dpyers
Date Posted: 11 November 2004 at 4:05pm

The on error will only return errors from the winhttp object - typically, about the only thing you'd see is a 404 if the url doesn't exist or some sort of code for an invalid header returned. Errors raised by the called page have to be resolved there. Anything invoked by global.asa needs to intercept errors so nothing gets to the screen. If your familiar with win client serve, it's like the difference between dcom and com - com can write to the screen, dcom, which executes on a remote machine should never do so.

The Application_OnStart subroutine can be called once a day, once a month, or once every few minutes - you don't really have any control over it.
If you're trying to run something once a day, It's more reliable if you put it in Session_OnStart and included code to check if it's been run today.

My personal preference for running scheduled events is to do it from a unix cron - use Lynx to run an asp script and route any output/errors to either a logfile or /dev/null. You can also go with 3rd-party services that will do this, but you can get a unix account with cron for $2 US/month and do it for many domains.

I usually dim and set a timestamp in the Application_OnStart event. I display it and some session count info on my homepages if the http_refferrer is my ip or something like debug=Y is passed in the url. Helps in situations like this.

WinHttp - I usually use server.XMLHTTP as it uses a reduced tcp/ip stack so it's faster . IIRC, WinHttp creates a new session - even if used locally - which may result in flakey things if used within global.asa. Might happen with Server.XMLHTTP also, but I've never really used it from an asa file.

If you want you can zip up your global.asa and the script you're trying to execute from it and pm me with them. I'll take a look at it - sometimes it's something S+S but just needs a fresh set of eyeballs to pick it up.



-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: Phat
Date Posted: 11 November 2004 at 8:48pm
I was starting to think i was going to get a unix account with cron jobs. I used to use script schedule but they closed down.

I even offered to buy the website but the guy never replied and just shut down the site.

Who is a good unix host who offer cron jobs?




Posted By: dpyers
Date Posted: 11 November 2004 at 10:02pm

I heve my own unix, but http://www.affordablehost.com - www.affordablehost.com  has free unix accounts and a decent reputation.
They're a cpanel shop which includes cron. You don't get email po boxes, but do get email forwards. No db with the free accounts.

a sample cron command to run a remote script at 8:05 AM, 12:05 PM, and 4:05 AM every day would look like...

5 8,12,16 * * * /usr/local/bin/lynx -dump /dev/null  http://www.mydomain.com/myfile.asp - http://www.mydomain.com/myfile.asp  > /dev/null

It's usually a good idea not to run stuff on the hour as everyone else seems to do it then - lol. The path to lynx will vary by host.



-------------

Lead me not into temptation... I know the short cut, follow me.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net