<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://v900u039rux.maximumasp.com/Web/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Raheel Hussain : HttpResponse</title><link>http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/tags/HttpResponse/default.aspx</link><description>Tags: HttpResponse</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP2 (Build: 20611.960)</generator><item><title>Find If page Exists on webserver without FTP</title><link>http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/2007/07/19/how-to-findout-the-existance-of-a-page-on-the-server-without-ftp.aspx</link><pubDate>Thu, 19 Jul 2007 13:01:00 GMT</pubDate><guid isPermaLink="false">3790bee0-d05b-4b84-a272-3ed522a0473a:24</guid><dc:creator>Raheel Hussain</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://v900u039rux.maximumasp.com/Web/blogs/raheel/rsscomments.aspx?PostID=24</wfw:commentRss><comments>http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/2007/07/19/how-to-findout-the-existance-of-a-page-on-the-server-without-ftp.aspx#comments</comments><description>&lt;p&gt;Suppose you have a web server, where you&amp;#39;ve hosted a website and you required to send a single page of the website (as a report) via email to the subscriber &lt;br /&gt;(or member) of the website.&lt;br /&gt;&lt;br /&gt;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). &lt;br /&gt;&lt;br /&gt;I faced a situation where I may receive a reference of the file through database values (i.e. filename.asp or filename.htm etc)&amp;nbsp;but the file is not there&amp;nbsp;on webserver ftp directory (or virtual directory to be served against the name).&amp;nbsp;&lt;br /&gt;&lt;br /&gt;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 &lt;br /&gt;(if ftp enabled),&amp;nbsp; but I was asked to display a default page for that particular system (CMS directory) &lt;/p&gt;
&lt;p&gt;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)&lt;/p&gt;
&lt;p&gt;However,&amp;nbsp; the server side script is more trustworthy for the above scenarios.&lt;br /&gt;I&amp;#39;ve implemented my logic in ASP.NET (vbscript) as follows. Hope this would help out somebody above of simillar situation is encountered.&lt;br /&gt;&lt;br /&gt;Following is the code whcih was used &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;div style="PADDING-LEFT:5px;PADDING-BOTTOM:5px;PADDING-TOP:1px;BACKGROUND-COLOR:#f3f3f3;"&gt;&lt;pre&gt;Private Sub getHTTPResponse(ByVal strURL As String)
        Dim objReq As HttpWebRequest
        Dim objResp As HttpWebResponse = Nothing
        Dim strRetVal As String = &amp;quot;&amp;quot;
        Dim oWebProxy As WebProxy
        Try
            oWebProxy = New WebProxy(&amp;quot;http://&lt;strong&gt;proxy_url:port&lt;/strong&gt;/&amp;quot;)
            WebRequest.DefaultWebProxy = oWebProxy
            oWebProxy.UseDefaultCredentials = True

            oWebProxy.BypassProxyOnLocal = True
            oWebProxy.Credentials = &lt;br /&gt;            New System.Net.NetworkCredential(&amp;quot;USER_NAME&amp;quot;, &amp;quot;PASSWORD&amp;quot;, &amp;quot;DOMAIN_NAME&amp;quot;)
            objReq = WebRequest.Create(strURL)

            objReq.PreAuthenticate = True
            objReq.Proxy = oWebProxy
            objReq.UseDefaultCredentials = True
            objResp = objReq.GetResponse()

            If Not (objResp Is Nothing) Then
                Response.Write&lt;br /&gt;           (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
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;
&lt;p&gt;The above code is using two objects to get the response from any of the website.&lt;br /&gt;Suppose if &lt;a href="http://yukonizer.com/Web/"&gt;http://yukonizer.com/Web/&lt;/a&gt;&amp;nbsp;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&amp;nbsp;that is, that it receives all the HTML response but obviously doesn&amp;#39;t download the images.&lt;br /&gt;&lt;br /&gt;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&lt;br /&gt;&lt;br /&gt;for example :&lt;br /&gt;&lt;br /&gt;if webPageExists (strURL) = true then&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39; &amp;#39; to put the hyper link your way&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt; a href = &amp;quot; url of the page&amp;nbsp;&amp;nbsp;&amp;quot; &amp;gt; Click here &amp;lt; /&amp;nbsp;a &amp;gt;&lt;br /&gt;end if &lt;br /&gt;&lt;br /&gt;A modified version of the above code is below &lt;/p&gt;
&lt;div style="PADDING-LEFT:5px;PADDING-BOTTOM:5px;PADDING-TOP:1px;BACKGROUND-COLOR:#f3f3f3;"&gt;&lt;pre&gt;Private Function webPageExists(ByVal strURL As String) As Boolean
        Dim objReq As HttpWebRequest
        Dim objResp As HttpWebResponse = Nothing
        Dim strRetVal As String = &amp;quot;&amp;quot;
        Dim oWebProxy As WebProxy
        Dim retVal As Boolean = False
        Try
            oWebProxy = New WebProxy(&amp;quot;http://proxy_url:port/&amp;quot;)
            WebRequest.DefaultWebProxy = oWebProxy
            oWebProxy.UseDefaultCredentials = True

            oWebProxy.BypassProxyOnLocal = True
            oWebProxy.Credentials = &lt;br /&gt;            New System.Net.NetworkCredential(&amp;quot;USER_NAME&amp;quot;, &amp;quot;PASSWORD&amp;quot;, &amp;quot;DOMAIN_NAME&amp;quot;)
            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

&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;The function call is as below;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;div style="PADDING-LEFT:5px;PADDING-BOTTOM:5px;PADDING-TOP:1px;BACKGROUND-COLOR:#f3f3f3;"&gt;&lt;pre&gt;      If webPageExists(&amp;quot;http://www.ddj.com&amp;quot;) = True Then
            Response.Write(&amp;quot;OKEY,&amp;quot;)
        Else
            Response.Write(&amp;quot;not OKEY,&amp;quot;)
        End If

&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Cheers !!! raheel Hussain&lt;img src="http://v900u039rux.maximumasp.com/Web/aggbug.aspx?PostID=24" width="1" height="1"&gt;</description><category domain="http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/tags/StreamReader/default.aspx">StreamReader</category><category domain="http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/tags/HttpResponse/default.aspx">HttpResponse</category><category domain="http://v900u039rux.maximumasp.com/Web/blogs/raheel/archive/tags/HttpRequest/default.aspx">HttpRequest</category></item></channel></rss>