3

我正在尝试在 C# 代码中读取 Web 资源。不幸的是,该代码仅在从本地驱动器运行时有效,并且在从网络共享运行时抛出异常(这就是我需要的)。

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)

我尝试过类似于(这会引发异常)的代码:

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

以及根据http://msdn.microsoft.com/en-us/library/2b86d684的直接套接字连接。

我怀疑 Windows 中有某种安全设置会阻止网络连接。有可能解决这个问题吗?通过广告策略?或者我的代码中有什么东西?

4

1 回答 1

4

您可以从“项目位置不受信任”对话框开始。引用:

默认情况下,UNC 路径不是项目的受信任位置。您可以修改文件共享的安全策略以防止出现此对话框。有关详细信息,请参阅配置安全策略

于 2012-09-10T14:23:28.377 回答