2015-05-08 17 views
5
  • IIS 7.5 2008 R2
  • più siti IIS Server/Windows legati alla stesso indirizzo IP, utilizzando nomi host.
  • Il traffico in entrata verso i siti funzionanti correttamente.
  • Le richieste Web in uscita eseguite dal codice sito back-end non riescono. Il sito remoto restituisce 404 (NotFound).
  • Verificato tramite una traccia di rete che il traffico sta raggiungendo il server di rimozione.
  • Le stesse richieste funzionano bene se effettuate da un sito che utilizza un indirizzo IP dedicato (ovvero non condiviso con altri siti).

Qualcuno ha qualche idea su come fare questo lavoro o cosa potrebbe andare storto?richieste Web in uscita quando non riescono a base di siti di IIS utilizzando l'indirizzo IP condiviso

traccia di Network sul server di hosting:

richiesta di successo dal sito w/non condivisa indirizzo IP:

No.  Time   Source    Destination   Protocol Info 
    6366 15:54:35.590463 192.168.1.76   173.194.77.121  HTTP  GET /key/value/one/two HTTP/1.1 
    6369 15:54:35.599879 173.194.77.121  192.168.1.76   TCP  http > 55407 [ACK] Seq=1 Ack=110 Win=344 Len=0 
    6370 15:54:35.621587 173.194.77.121  192.168.1.76   HTTP  HTTP/1.1 200 OK (application/json) 
    6608 15:54:35.815774 192.168.1.76   173.194.77.121  TCP  55407 > http [ACK] Seq=110 Ack=357 Win=509 Len=0 

richiesta non riuscita dal sito utilizzando un indirizzo IP condiviso:

No.  Time   Source    Destination   Protocol Info 
    9720 15:54:39.244192 192.168.1.80   173.194.77.121  HTTP  GET /key/value/one/two HTTP/1.1 
    9760 15:54:39.256958 173.194.77.121  192.168.1.80   TCP  [TCP segment of a reassembled PDU] 
    9761 15:54:39.256962 173.194.77.121  192.168.1.80   HTTP  HTTP/1.1 404 Not Found (text/html) 
    9762 15:54:39.257027 192.168.1.80   173.194.77.121  TCP  55438 > http [ACK] Seq=212 Ack=1676 Win=512 Len=0 

Codice:

public static HttpWebRequest CreateWebRequest(string url, string method = "GET", string referer = null, string contentType = null, int timeout = 100000, string authentication = null, string bindToIpAddress = null, string host = null) 
{ 
    var request = (HttpWebRequest)WebRequest.Create(url); 

    if (!string.IsNullOrWhiteSpace(bindToIpAddress)) 
    { 
     IPAddress bindIp; 
     if (!IPAddress.TryParse(bindToIpAddress, out bindIp)) 
     { 
      throw new ArgumentException("bindToIpAddress"); 
     } 

     request.ServicePoint.BindIPEndPointDelegate = ((sp, rep, rc) => 
     { 
      return new IPEndPoint(bindIp, 0); 
     }); 
    } 

    request.Accept = "*/*"; 
    request.ContentType = contentType; 
    request.Referer = referer; 
    request.Method = method; 
    request.Timeout = timeout; 

    if (!string.IsNullOrWhiteSpace(host)) 
    { 
     request.Host = host; 
    } 

    return request; 
} 

string GetData() 
{ 
    try 
    { 
     string result; 

     var request = CreateWebRequest("http://jsonplaceholder.typicode.com/posts/1", 
             "GET", 
             "somedomain.com", 
             timeout: (10 * 1000), 
             bindToIpAddress: "192.168.27.133" /*site IP*/); 

     request.Accept = "application/json"; 

     using (var response = request.GetResponse()) 
     { 
      using (var sr = new StreamReader(response.GetResponseStream())) 
      { 
       result = sr.ReadToEnd(); 
      } 
     } 

     return result; 
    } 
    catch (Exception ex) 
    { 
     return null; 
    } 
} 
+1

Domanda sciocca ma sono gli indirizzi IP dedicati e condivisi provenienti dallo stesso ISP? C'è qualche possibilità che il vostro IP condiviso sia inserito nella lista nera? – Jacques

+0

Sì. Stesso ISP e ambiente di hosting, Rackspace, per entrambi gli IP. Nella lista nera dove? Con il servizio esterno? Succede con tutti i servizi web di terze parti che abbiamo provato. Non penso che tutti starebbero nella lista nera dell'IP? –

+0

Hai eseguito un IISReset dopo aver cambiato gli IP da Dedicated a Shared? –

risposta

0

Questo si è rivelato un bug nella nostra applicazione. In alcuni casi, l'intestazione host (proprietà Host sulla richiesta) veniva impostata in modo errato (sul nome host del sito di hosting/sorgente). L'esempio del codice ridotto nella domanda non lo mostra. Va bene per i servizi web che hanno ignorato l'intestazione ed è stato un problema (404 risposta) per gli altri che hanno fatto non ignorare l'intestazione. Il problema non aveva nulla da fare con IIS o l'indirizzo IP condiviso. Grazie per tutte le risposte.

+0

[Dexion] (http://stackoverflow.com/users/460275/dexion) era azzeccato. –

0

La risposta 404 viene restituita dal sito remoto, pertanto il sito remoto non riesce a elaborare la richiesta e non ha nulla a che fare con ciò che accade sul server locale.

L'unica differenza dal punto di vista del sito remoto è l'indirizzo IP del mittente, quindi deve essere configurato per accettare richieste solo da determinati indirizzi IP. Questa restrizione potrebbe essere nel server remoto o in qualsiasi firewall, router o proxy in mezzo.

Problemi correlati