无法从远程桌面访问本地iis

时间:2017-06-30 10:46:28

标签: c#-4.0 asp.net-web-api iis-7

这是我得到的错误:

System.AggregateException: One or more errors occurred. 
---> System.Net.Http.HttpRequestException: An error occurred while sending the request. 
---> System.Net.WebException: Unable to connect to the remote server 
---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 172.26.17.212:8080\r\n  
 at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)\r\n   at System.Net.ServicePoint.
ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)\r\n 
  --- End of inner exception stack trace ---\r\n   at System.Net.HttpWebRequest.
EndGetResponse(IAsyncResult asyncResult)\r\n   at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)\r\n   
--- End of inner exception stack trace ---\r\n   --- End of inner exception stack trace ---\r\n   at System.Threading.
Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)\r\n   at Web_Api_ServerTest.Controllers.EmployeeController.
<Login>d__0.MoveNext()\r\n---> (Inner Exception #0) System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.Net.WebException: Unable to connect to the remote server
 ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 172.26.17.212:8080\r\n  
 at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)\r\n   at System.
Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)\r\n  

以下是我认为导致此问题的代码:

 [ActionName("Login")]
    [HttpGet]
    [CacheFilter(TimeDuration = 100)]
    public async Task<string> Login([FromUri]string id, string netPwd)
    {
      using (HostingEnvironment.Impersonate())
        {
            try
            {
                HttpClientHandler hndlr = new HttpClientHandler();
                hndlr.UseDefaultCredentials = true;
                HttpClient client = new HttpClient(hndlr);

                 client.BaseAddress = new 
               Uri("http://172.26.17.212/webapi_publish/api/employee/Login/" 
                 + id + "?netpwd=" + netPwd);

                // Add an Accept header for JSON format.
                client.DefaultRequestHeaders.Accept.Add(
               new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = client.GetAsync(client.BaseAddress).Result;

                if (response.IsSuccessStatusCode)
                {
                    dt = response.Content.ReadAsStringAsync().Result;
                }
            }

            catch (Exception ex)
            {

                dt = ex.ToString();
            }
        }
        return dt;
  }

1 个答案:

答案 0 :(得分:0)

从您收到的错误中,您似乎无法访问服务器的http端口。

请管理员检查您的网络设置是否正常,或允许此端口在防火墙中访问。