M
Mad Scientist Jr
For some reason I can't get a WebClient to access an outside URL from
behind our firewall. The code works when it runs outside the firewall.
I turned on windows authentication in the web.config
<authentication mode="Windows" />
and set up IIS to not allow anonymous access.
My browser is set up to auto detect the proxy server, so IE/Firefox can
access outside pages, so I added code to auto-detect the proxy server.
But still the function returns the error:
"The underlying connection was closed: Unable to connect to the remote
server."
Can someone explain how to get it to work from behind our firewall? My
code is below.
Thanks in advance...
'goto a URL and retrieve text from page
Private Function GetHtml(byval sURL as String) As String
Dim WebClient As New System.Net.WebClient
Dim webResponse As IO.Stream
Dim webResult As String
Dim myReader As IO.StreamReader
Try
'problem with credentials? attemt #1
'TODO: redo this to automatically detect if "anonymous access"
is enabled in IIS
'If
System.Configuration.ConfigurationSettings.AppSettings.Get("AnonymousAccessEnabled")
<> "1" Then
' WebClient.Credentials =
System.Web.HttpContext.Current.User.Identity
' ' ' System.Web.HttpContext.Current.User.Identity
' ' 'WebClient.Credentials =
' ' 'System.Net.ICredentials
'End If
'access web thru proxy:
'GlobalProxySelection.Select = New WebProxy("proxy", 8080)
GlobalProxySelection.Select = WebProxy.GetDefaultProxy
webResponse = WebClient.OpenRead(remoteFile)
'objWebClient.DownloadData (strURL)
myReader = New IO.StreamReader(webResponse)
webResult = myReader.ReadToEnd
myReader.Close()
webResponse.Close()
Return webResult
Catch ex As Exception
HandleWebError(ex)
End Try
End Function ' GetHtml
behind our firewall. The code works when it runs outside the firewall.
I turned on windows authentication in the web.config
<authentication mode="Windows" />
and set up IIS to not allow anonymous access.
My browser is set up to auto detect the proxy server, so IE/Firefox can
access outside pages, so I added code to auto-detect the proxy server.
But still the function returns the error:
"The underlying connection was closed: Unable to connect to the remote
server."
Can someone explain how to get it to work from behind our firewall? My
code is below.
Thanks in advance...
'goto a URL and retrieve text from page
Private Function GetHtml(byval sURL as String) As String
Dim WebClient As New System.Net.WebClient
Dim webResponse As IO.Stream
Dim webResult As String
Dim myReader As IO.StreamReader
Try
'problem with credentials? attemt #1
'TODO: redo this to automatically detect if "anonymous access"
is enabled in IIS
'If
System.Configuration.ConfigurationSettings.AppSettings.Get("AnonymousAccessEnabled")
<> "1" Then
' WebClient.Credentials =
System.Web.HttpContext.Current.User.Identity
' ' ' System.Web.HttpContext.Current.User.Identity
' ' 'WebClient.Credentials =
' ' 'System.Net.ICredentials
'End If
'access web thru proxy:
'GlobalProxySelection.Select = New WebProxy("proxy", 8080)
GlobalProxySelection.Select = WebProxy.GetDefaultProxy
webResponse = WebClient.OpenRead(remoteFile)
'objWebClient.DownloadData (strURL)
myReader = New IO.StreamReader(webResponse)
webResult = myReader.ReadToEnd
myReader.Close()
webResponse.Close()
Return webResult
Catch ex As Exception
HandleWebError(ex)
End Try
End Function ' GetHtml