3

I'm trying to read web resource fron within the C# code. Unfortunately the code is valid only when running from local drive and throws exception when running from network share (and that's what I need).

The underlying connection was closed: Unable to connect to the remote server.
   in System.Net.HttpWebRequest.GetResponse()
   .........
Caused by: 
An invalid argument was supplied
   in System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
   in System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
   in System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
   in System.Net.Connection.CompleteStartConnection(Boolean async, HttpWebRequest httpWebRequest)

I've tried code similar to (this throws the exception):

request = (HttpWebRequest)WebRequest.Create(url);

as well as direct socket connection according to http://msdn.microsoft.com/en-us/library/2b86d684.

I have a suspicion there is some sort of security setting in Windows that prevents network connections. Is it possible to solve this? Via AD policy? Or something in my code?

Lukas
  • 115
  • 2
  • 11
  • Did you debug through? What `url` throws? Does the same URL causes the app to throw when it runs locally? – Oded Sep 10 '12 at 14:19
  • Maybe this can help : http://blogs.msdn.com/b/josefve/archive/2009/10/20/net-code-access-security-and-using-a-network-drive-or-a-unc-path-for-your-assembly.aspx, http://stackoverflow.com/questions/1047243/net-code-access-security-useful-or-just-overcomplicated – Steve B Sep 10 '12 at 14:21

1 Answers1

4

You could start here The Project Location is Not Trusted Dialog Box. Quote:

By default, a UNC path is not a trusted location for a project. You can modify the security policy of the file share to prevent this dialog box from appearing. For more information, see Configuring Security Policy.

aiodintsov
  • 2,545
  • 15
  • 17