ASP.NET - Run .aspx page with Windows Task Scheduler

Asked By Jem Savery on 20-Nov-11 12:05 PM
Hi Friends, 

I have a url like this:

http://mydomain.com/Scheduled_Page.aspx

I want to run this page every 10 minutes on server with Windows task scheduler. 

I added .vbs page with following code to scheduler and set the time for "Daily" and "Every 10 minutes" in Advanced settings of the scheduler.

Dim oWinHTTP
Set oWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
oWinHTTP.Open "GET", "http://mydomain.com/Scheduled_Page.aspx", False
oWinHTTP.Send

But is is not giving the effect, it means, the page is not running.

What can I do to solve this issue?


Thanks.
Neha Garg replied to Jem Savery on 20-Nov-11 12:14 PM
Hello Jem,

Call LogEntry()
  
Sub LogEntry()
  
    On Error Resume Next
  
    Dim objRequest
    Dim URL
  
    Set objRequest = CreateObject("Microsoft.XMLHTTP")
    URL = "http://mydomain.com/Scheduled_Page.aspxhttp://www.your_website.com/filename.aspx"
  
    objRequest.open "POST", URL , false
  
    objRequest.Send
  
    Set objRequest = Nothing
  
End Sub
 
Read more: http://4rapiddev.com/internet/call-or-open-a-web-page-url-by-using-windows-task-scheduler-or-cronjob/#ixzz1eGb3IF75
Suchit shah replied to Jem Savery on 20-Nov-11 12:15 PM

You can create scheduled tasks for .aspx files by scheduling your .aspx files to run using iexplore.exe:

Start –> Control panel –> Scheduled Tasks –> Add scheduled task

Then, browse for your .aspx file and select it.

After creating scheduled task, go through Start –> Control panel –> Scheduled Tasks and select the properties of the newly created task.

Suppose, you want to schedule http://192.168.1.0/ScheduleMe.aspx, then the “run” field should looks like:

“C:\Program Files\Internet Explorer\IExplore.exe” http://192.168.1.0/ScheduleMe.aspx

By default, IExplore.exe opens a browser each time it runs. In order to close the browser you may have to schedule another task. Here is a very simple task to close the IE browser:

taskkill /IM iexplore.exe

Open your notepad and save the file as .bat (say IEkill.bat) after entering the line above. Schedule this to run after 5 or 10 minutes.

Neha Garg replied to Neha Garg on 20-Nov-11 12:17 PM
Jem,

Here is one more example for running .aspx page with Windows Task Scheduler:

Call LogEntry()
 
Sub LogEntry()
 
    ‘Force the script to finish on an error.
    On Error Resume Next
 
    'Declare variables
    Dim objRequest
    Dim URL
 
    Set objRequest = CreateObject("Microsoft.XMLHTTP")
 
    'Put together the URL link appending the Variables.
    URL = "http://mydomain.com/Scheduled_Page.aspxhttp://www.your_website.com/filename.aspx"http://www.yourdomain.com/track.aspx
 
    'Open the HTTP request and pass the URL to the objRequest object
    objRequest.open "POST", URL , false
 
    'Send the HTML Request
    objRequest.Send
 
    'Set the object to nothing
    Set objRequest = Nothing
 
End Sub
Suchit shah replied to Jem Savery on 20-Nov-11 12:19 PM
Here are steps to get started.
Write your VBS Script
Develop the webpage to process the HTTP Request 
Schedule the VBS Script
Write your VBS script

The script makes an HTTP request to a webpage on a timed basis. (i.e. every 5 minutes). 

YourVBScript.vbs 
 Call LogEntry() 
 Sub LogEntry() 
     'Force the script to finish on an error. 
     On Error Resume Next 
     Declare variables 
     Dim objRequest 
     Dim URL 
     Set objRequest = CreateObject("Microsoft.XMLHTTP") 
     'Put together the URL link appending the Variables. 
     URL = "http://www.YourDomain.com/track.aspx" 
     'Open the HTTP request and pass the URL to the objRequest object 
     objRequest.open "POST", URL , false 
     'Send the HTML Request 
     objRequest.Send 
     'Set the object to nothing 
     Set objRequest = Nothing 
 End Sub 


Tracklog.aspx webpage 
<%@ Page Language="VB" AutoEventWireup="false" codefile="tracklog.aspx.vb" Inherits="Tracklog"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
     <head runat="server"> 
        <title>Log Page</title> 
     </head> 
          <body> 
            <form id="form1" runat="server"> 
            <div></div> 
            </form> 
        </body> 
</html> 


Tracklog.aspx.vb code behind 
Imports System.Data 
Imports System.Data.SqlClient 
Imports System.Configuration 

Partial Class Tracklog  Inherits System.Web.UI.Page 
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          ‘Put your code in that would process when Track.aspx is request 
           Response.write(“Track.aspx was called:” & System.DateTime.Now()) 
     End Sub 
End Class


How to schedule a task using Windows Task Scheduler 
A scheduled task will allow a person to schedule any script, program, or document to run. Scheduled Tasks run at the time specified which could be multiple times per minute, hour, or day. The KB Article explains step-by-step. 
http://support.microsoft.com/default.aspx?scid=kb;en-us;308569&sd=tech
Devil Scorpio replied to Jem Savery on 20-Nov-11 01:43 PM
Hi,

You can write a .vbs script file and schedule .aspx page as Windows task (CScript C:\YourScript.vbs //H:CScript).

YourScript.vbs

Call Send_HTTP_Request()

Sub Send_HTTP_Request()

On Error Resume Next

Dim objRequest
Dim URL

Set objRequest = CreateObject("Microsoft.XMLHTTP")

URL = "http://www.yourdomain.com/your_page.aspx"

objRequest.open "POST", URL , false

objRequest.Send

Set objRequest = Nothing

End Sub