Suppose you have a web server, where you've hosted a website and you required to send a single page of the website (as a report) via email to the subscriber
(or member) of the website.
Or Suppose that you have a content management system running on a website which generates/publish pages, those pages are to be displayed through your web application with Response.Redirect command. But before doing that, you need to ensure that the page really existing there (i.e. published to the server).
I faced a situation where I may receive a reference of the file through database values (i.e. filename.asp or filename.htm etc) but the file is not there on webserver ftp directory (or virtual directory to be served against the name).
Although on web server part we can have a Page Not Found document which can be displayed instead, as well as we can use some ftp component programmatically
(if ftp enabled), but I was asked to display a default page for that particular system (CMS directory)
Both of the situations above can be solved through server side script as well as client side script (making use of FSO through CreateObject etc)
However, the server side script is more trustworthy for the above scenarios.
I've implemented my logic in ASP.NET (vbscript) as follows. Hope this would help out somebody above of simillar situation is encountered.
Following is the code whcih was used
Private Sub getHTTPResponse(ByVal strURL As String)
Dim objReq As HttpWebRequest
Dim objResp As HttpWebResponse = Nothing
Dim strRetVal As String = ""
Dim oWebProxy As WebProxy
Try
oWebProxy = New WebProxy("http://proxy_url:port/")
WebRequest.DefaultWebProxy = oWebProxy
oWebProxy.UseDefaultCredentials = True
oWebProxy.BypassProxyOnLocal = True
oWebProxy.Credentials =
New System.Net.NetworkCredential("USER_NAME", "PASSWORD", "DOMAIN_NAME")
objReq = WebRequest.Create(strURL)
objReq.PreAuthenticate = True
objReq.Proxy = oWebProxy
objReq.UseDefaultCredentials = True
objResp = objReq.GetResponse()
If Not (objResp Is Nothing) Then
Response.Write
(New System.IO.StreamReader(objResp.GetResponseStream).ReadToEnd)
End If
Catch ex As Exception
Response.Write(ex.Message)
Finally
objReq = Nothing
objResp = Nothing
End Try
End Sub
The above code is using two objects to get the response from any of the website.
Suppose if http://yukonizer.com/Web/ is passed as an argument to the above function, it will display all the HTML except the images will not be displayed. The reason for that is, that it receives all the HTML response but obviously doesn't download the images.
Images or other simillary contents are displayed with the relative path rather than the absolute URL path. So the text based pages can be displayed. And as we know the prime requirement for which I did the code was to findout whether any particular page exists at a certain path or before we go to include and wrap it in an anchor tag
for example :
if webPageExists (strURL) = true then
' ' to put the hyper link your way
< a href = " url of the page " > Click here < / a >
end if
A modified version of the above code is below
Private Function webPageExists(ByVal strURL As String) As Boolean
Dim objReq As HttpWebRequest
Dim objResp As HttpWebResponse = Nothing
Dim strRetVal As String = ""
Dim oWebProxy As WebProxy
Dim retVal As Boolean = False
Try
oWebProxy = New WebProxy("http://proxy_url:port/")
WebRequest.DefaultWebProxy = oWebProxy
oWebProxy.UseDefaultCredentials = True
oWebProxy.BypassProxyOnLocal = True
oWebProxy.Credentials =
New System.Net.NetworkCredential("USER_NAME", "PASSWORD", "DOMAIN_NAME")
objReq = WebRequest.Create(strURL)
objReq.PreAuthenticate = True
objReq.Proxy = oWebProxy
objReq.UseDefaultCredentials = True
objResp = objReq.GetResponse()
If Not (objResp Is Nothing) Then
retVal = True
Else
retVal = False
End If
Return retVal
Catch ex As Exception
Return False
Finally
objReq = Nothing
objResp = Nothing
End Try
End Function
The above code is supposed to display whether the the site exists as well as will let you whether any specific page on the site exists.
The function call is as below;
If webPageExists("http://www.ddj.com") = True Then
Response.Write("OKEY,")
Else
Response.Write("not OKEY,")
End If
Cheers !!! raheel Hussain