C# network connection running from shared drive

牧云@^-^@ 提交于 2019-11-27 07:17:22

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/12353586/c-sharp-network-connection-running-from-shared-drive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!