schedule webpage - asp.net

I need to schedule several different pages on several different sites to be run at certain times, usually once a night. Is there any software out there to do this? it would be nice if it called the page and then recorded the response and whether the called page was successful run or not. I was using Helm on a different box and it had a nice Web Scheduler module but Helm is not an option for this machine. This is a Window Server 2008 box.

We use standard scheduled tasks that call a bat file that calls a VBS file. I know it is not the most elegant solution ever, but it consistently works.
BAT:
webrun.vbs http://website.com/page.aspx
VBS:
dim URL, oArgs
Set oArgs = WScript.Arguments
if oArgs.Count = 0 then
msgbox("Error: Must supply URL")
wscript.quit 1
end if
URL = oArgs(0)
on error resume next
Set objXML = CreateObject("MSXML2.ServerXMLHTTP")
if err then
msgbox("Error: " & err.description)
wscript.quit 1
end if
' Call the remote machine the request
objXML.open "GET", URL, False
objXML.send()
' return the response
'msgbox objXML.responSetext
' clean up
Set objXML = Nothing
The code in the VBS file is almost assuredly both overkill and underwritten, but functional none-the-less.

How about wget.exe and the task scheduler?

The code given in the upper example has some issues with the task being active during the loading of the website. The website is loading 2 minutes but the task is already done in 1 second, which brings a problem when you execute it every 5 minutes. If the website loads 10 minutes and the task is already done in 1 second it wil execute again that while I want it to wait the loading time of the website.
So what I've done is the following (this script will keep the task busy as long the website is loading):
dim URL, oArgs, objXML
Set oArgs = WScript.Arguments
URL = oArgs(0)
on error resume next
Set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = "false"
objXML.load(URL)
Set objXML = Nothing

If it's not a requirement to schedule them from the same box, have a look to Zoho's site24x7.
It is initially designed to monitor web sites but it has an option to record expected answers and compare them so you can use it for your purpose with the added security of an external site. It's not free however except for few urls.
They are other similar providers but they looked pretty good last time I searched the web on this topic.

I ended up using this script and Task Scheduler, simple and works great:
Call LogEntry()
Sub LogEntry()
'Force the script to finish on an error.
On Error Resume Next
'Declare variables
Dim objRequest
Dim URLs
URLs = Wscript.Arguments(0)
Set objRequest = CreateObject("Microsoft.XMLHTTP")
'Open the HTTP request and pass the URL to the objRequest object
objRequest.open "POST", URLs, false
'Send the HTML Request
objRequest.Send
Set objRequest = Nothing
WScript.Quit
End Sub
Then I just call it with the URL I want run as an argument:

Similar (though possibly more powerful) is netcat and its windows port

fyi - wget is GNU standard license, so I'm not sure it's usable for most commercial/proprietary systems.

I use http://scheduler.codeeffects.com. Very effective and reliable, no complains.

Related

Why is Request.Files.Count sometimes 0 using HTML5 uploader?

We're using plupload for users to upload files to our VPS.
Here is the plupload code:
var uploader = new plupload.Uploader({
browse_button: 'fileSelectorLink',
container: 'uploadContainer',
drop_element: 'uploadbox',
url: '/UploadHandler.ashx',
unique_names: true,
multi_selection: false,
flash_swf_url: '/scripts/plupload/js/Moxie.swf',
silverlight_xap_url: '/scripts/plupload/js/Moxie.xap'
});
He is the code for processing the request:
Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim runtime As String = If(context.Request("runtime") IsNot Nothing, context.Request("runtime"), "Unknown")
If context.Request IsNot Nothing Then
If context.Request.Files.Count > 0 Then
Dim fileUpload As HttpPostedFile = context.Request.Files(0)
...
Else
' Throw an exception
End If
End Sub
Occasionally (about 2% of the time) the exception will get thrown. Here is an example of request that threw an error:
Runtime: html5
Request.ContentType: multipart/form-data; boundary=----WebKitFormBoundaryo7JAtlhKsg8xDcQT
Request.ContentLength: 3758089
Request.ContentEncoding: System.Text.SBCSCodePageEncoding
Request.TotalBytes: 3179067
The errors seem to happen across different browsers and OSs (even modern browsers), so that doesn't seem to be the issue. Plupload should fall back to other versions if browser doesn't handle async file uploads. I thought the ContentEncoding seemed odd, but it seems to always say that (maybe plupload works like that?). The only thing that jumped out at me is that the ContentLength and TotalBytes were different, but in my local testing they were the same. Could that be a problem?
Been stuck on this issue for a few days and haven't had any good leads.
The failures could be occurring when users abort the upload (usually indicated by "The remote host closed the connection." exceptions), are encountering network latency, perhaps from HTTP timeouts, maybe even an issue with the Plupload code. My apologies for not being specific with the reason, however I believe I can make up for it by providing a solution that could limit issues encountered by users on your site.
Plupload contains a setting that will retry the upload upon encountering a HTTP error response. Use the max_retries setting so that in an instance where there is a "network hiccup", another attempt (or few) is/are done to retry the upload. Of course you'll still see the exceptions, but this may prevent the users from having to click the upload button again.
Your code would then become:
var uploader = new plupload.Uploader({
browse_button: 'fileSelectorLink',
max_retries: 2,
container: 'uploadContainer',
drop_element: 'uploadbox',
url: '/UploadHandler.ashx',
unique_names: true,
multi_selection: false,
flash_swf_url: '/scripts/plupload/js/Moxie.swf',
silverlight_xap_url: '/scripts/plupload/js/Moxie.xap'
});
Additionally, you can use a binary stream instead of multipart to post the file, which may alleviate issues with older browsers. You control this with the multipart setting.

CDOSYS : how to check if it's working?

On a client server, we have a little script that send an email at the end of an order, just before closing it.
Until yesterday everything works fine, but suddenly, the page gives a generic 500 error.
so I start from the bottom of the page find that if I put a response.end just before the .send of the cdo mail function, the page works fine:
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds(cdoSendUsingMethod) = cdoSendUsingPort
Flds(cdoSMTPServer) = "mail.theserver.com"
Flds(cdoSMTPServerPort) = 25
Flds(cdoSMTPAuthenticate) = cdoAnonymous '0
Flds.Update
With iMsg
Set .Configuration = iConf
.To = "mymail#mail.com"
.From = "amail#mail.gov"
.Sender = ""
.Subject = "test"
.HTMLBody = "TEST"
RESPONSE.END()
.Send
End With
On the page there are also two lines at the beginning:
<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Type Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
Well, I’ve already done some test putting some script to send emails a little different from this one but nothing seems to work. Does anybody know a way to test the cdosys? Something that. I don't know, return the version... or a list of options... well, something that makes me know that the error is on the server (and so I could phone to them and tell "hey it's not my fault")...?
Edit:
Since the page gives only a 500 error, is there a way to makes the server returns a more specific error code? i can't access the server, but only the ftp (so only classic asp)
Edit 2: i have add this code:
on error resume next
.Send
If Err.Number <> 0 Then
Response.write(Err.Number)
response.write("<br>")
response.write(Err.description)
end if
and it gives this message:
-2147220975
Impossibile inviare il messaggio al server SMTP. Codice errore di trasporto: 0x800ccc6f. Risposta del server: 554 Your access to this mail system has been rejected due to the sending MTA's poor reputation.
Based on your error message the CDO component is working but your SMTP sever (MTA) is rejecting the message. Maybe because of the .gov domain? Regardless you have a poor SMTP reputation for spamming. You need to use a different SMTP server. If you are using the ip of the IIS server, than that IP is no longer good, and has been blacklisted by spam servers.
Mailchimp has a lot of information on mail deliverable. Take a look at it.
You can use a hosted SMTP service (mailgun, sendgrid, mandrill), all of which will block you right away if you are spamming.

Request.Form between HTTP and HTTPS pages in ASP.NET

I have a strange situation and google isn't helping me out. I have an admin site which is in simple HTTP who posts data to a different site running under HTTPS. The HTTP admin site (which I don't have direct access to) is sending the info via basic POST, and I'm trying to capture the Request.Form values in the HTTPS site. It works perfectly well in dev, due to the fact that the receiving site isn't running under SSL, but in prod, I have the Request.Form as empty. Someone could enlighten me? The basic HTTPS request code is below:
Dim nvm As NameValueCollection = Request.Form
Dim _idInscricao As String
Dim _Origem As String
litMensagem.Text = "Wait..."
If nvm.Keys.Count = 0 Then
litMensagem.Text = "Error recovering data. No keys found."
Exit Sub
End If
For Each _Key As String In nvm.Keys
If _Key.ToLower.EndsWith("idinscricao") Then
_idInscricao = nvm(_Key)
End If
If _Key.ToLower.EndsWith("origem") Then
_Origem = nvm(_Key)
End If
Next
If _idInscricao Is Nothing OrElse String.IsNullOrEmpty(_idInscricao) _
OrElse _Origem Is Nothing OrElse String.IsNullOrEmpty(_Origem) Then
litMensagem.Text = "Error recovering data."
Exit Sub
End If
I found this question because I was having the same problem, and I need to thank dana for the fiddler recommendation.
Using Fiddler, I found out what was going on. My page was on HTTPS, and the form that I was posting posted to HTTP. I couldn't figure out why my form structure on the posted page was empty.
Turns out the server couldn't find the http version of the file and did an automatic redirect to the https version, doing a GET with my form variables. They aren't available in the form scope with a GET. (FWIW, I'm using CFML.)
Once I changed the form action to post to HTTPS, everything worked like a charm.
-jason

ASP.NET & IIS 7.0 -- HTTPS Site Warmup Script

I have an ASP.NET 4.0 site on IIS 7.0 that is having first time load issues described here.
I've done some testing, and can confirm that it's only the first load of the page that is slow; every subsequent page loads normally. After googling around for this, I found a "warmup" script that can send an HTTP request the first time after the app pool is recycled, and this seems to fix the problem. BUT, I'm not sure if it will work when I force set the page to use only HTTPS/SSL?
The script I'm currently using is as follows:
Dim website1
website1 = "http://<website domain>/Auth/Login.aspx"
Function WarmUpSite(strURL)
On Error Resume Next
Dim objHTTP
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
objHTTP.Open "GET", strURL, False
objHTTP.Send
If Err.Number=0 And objHTTP.Status=200 Then
Hget=strURL & " has been warmed up successfully at: "&Date()&" "&Time()
Else
Hget=strURL & " found error at: "&Date()&" "&Time()
End If
Set objHTTP = Nothing
'Section for writing into a text file
Const FOR_APPENDING = 8
strFileName = "C:\WarmUpLog.txt"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strFileName,FOR_APPENDING)
objTS.WriteLine Hget
End Function
WarmUpSite(website1)
So my question is how I would make this work if the website I'm warming up is a login page that will be an HTTPS address, not HTTP? My apologies if this is a dumb question, I do relatively little web work.
Well, apparently it just involved changing the value of website1 to an HTTPS url.
;)

401 Unauthorised errors when attempting to download ASP page to file

Issue
Msxml2.ServerXMLHTTP keeps returning 401 - Unauthorised errors each time we attempt to read the contents of a file (ASP) from a web server.
Source server is running IIS6, using NTLM integrated login.
This process has been used successfully before, but only in as far as extracting XML files from external websites, not internal ones.
The proxy settings in the registry of the server on which the script is run has also been updated to bypass the website in question, but to no avail.
All paths identified in the VBScript have been checked and tested, and are correct.
User running the script has correct read/write permissions for all locations referenced in the script.
Solution needed
To identify the cause of the HTTP 401 Unauthorised messages, so that the script will work as intended.
Description
Our organisation operates an intranet, where the content is replicated to servers at each of our remote sites. This ensures these sites have continued fast access to important information, documentation and data, even in the event of losing connectivity.
We are in the middle of improving the listing and management of Forms (those pesky pieces of paper that have to be filled in for specific tasks). This involves establising a database of all our forms.
However, as the organisation hasn't been smart enough to invest in MSSQL Server instances at each site, replication of the database and accessing it from the local SQL server isn't an option.
To work around this, I have constructed a series of views (ASP pages) which display the required data. I then intend to use Msxml2.ServerXMLHTTP by VBScript, so I can read the resulting pages and save the output to a static file back on the server.
From there, the existing replication process can stream these files out to the site - with users having no idea that they're looking at a static page that just happened to be generated from database output.
Code
' Forms - Static Page Generator
' Implimented 2011-02-15 by Michael Harris
' Purpose: To download the contents of a page, and save that page to a static file.
' Target category: 1 (Contracts)
' Target Page:
' http://sharename.fpc.wa.gov.au/corporate/forms/generator/index.asp
' Target path: \\servername\sharename\corporate\forms\index.asp
' Resulting URL: http://sharename.fpc.wa.gov.au/corporate/forms/index.asp
' Remove read only
' Remove read only flag on file if present to allow editing
' If file has been set to read only by automated process, turn off read only
Const READ_ONLY = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("\\server\sharename\corporate\forms\index.asp")
If objFile.Attributes AND READ_ONLY Then
objFile.Attributes = objFile.Attributes XOR READ_ONLY
End If
Dim webObj, strURL
Set webObj = CreateObject("Msxml2.ServerXMLHTTP")
strURL = "http://sharename.fpc.wa.gov.au/corporate/forms/generator/index.asp"
webObj.Open "GET", strURL
webObj.send
If webObj.Status=200 Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Set txtFile = objFso.OpenTextFile("file:\\servername.fpc.wa.gov.au\sharename\corporate\forms\index.asp", 2, True)
txtFile.WriteLine webObj.responseText
txtFile.close
ElseIf webObj.Status >= 400 And webObj.Status <= 599 Then
MsgBox "Error Occurred : " & webObj.Status & " - " & webObj.statusText
Else
MsgBox webObj.ResponseText
End If
Replace your line:
webObj.Open "GET", strURL
With:
webObj.Open "GET", strURL, False, "username", "password"
In most cases 401 Unauthorized means you haven't supplied credentials. Also you should specifiy False to indicate you don't want async mode.
It sounds like the O.P. got this working with the correct proxy settings in the registry (http://support.microsoft.com/kb/291008 explains why proxy configuration will fix this). Newer versions of ServerXMLHTTP have a setProxy method that can be used to set the necessary proxy configuration in your code instead.
In the O.P. code above, after webObj is created, the following line of code would set up the proxy correctly:
webObj.setProxy 2, "0.0.0.0:80", "*.fpc.wa.gov.au"
ServerXMLHTTP will pass on the credentials of the user running the code if it is configured with a proxy, and if the target URL bypasses that proxy. Since you are bypassing the proxy anyway, you can make it a dummy value "0.0.0.0:80", and make sure your target url is covered by what you specify in the bypass list "*.fpc.wa.gov.au"
I would first test if you can reach your url through a normal browser on the same server X you run your code on (A). I would try then reach the url from another PC. One never used to reach that url but in the same network as server X (B).
If B works but A doesn't I would suspect that for some reason your source server (i.e. that one that serves the url) blocks server X for some reason. Check the security settings of II6 and of NTLM.
If both A and B don't work, there is something wrong more in general with your source server (i.e. it blocks everything or NTML doesn't allow you in).
If A works (B doesn't matter then), the problem has to be somewhere in your code. In that case, I would recommend fiddler. This tool can give you the HTTP requests of both your browser and your code in realtime. You can then compare both. That should give you at least a very strong hint about (if not immediately give you) the solution.

Resources