title: How to get client IP address in MVC 4 controller?
body: <p>I tried to get client IP adress in controller. It is working but sometimes I get this error:</p>
  
  <pre><code>The underlying connection was closed: An unexpected error occurred on a receive
  
  
          String IP = "";
  
          using (WebResponse response = request.GetResponse())
          {
              using (StreamReader stream = new StreamReader(response.GetResponseStream()))
              {
                  IP = stream.ReadToEnd();
              }
          }
  
          int first = IP.IndexOf("Address: ") + 9;
          int last = IP.LastIndexOf("&lt;/body&gt;");
          IP = IP.Substring(first, last - first);
  </code></pre>
  
  <p>Is there any different method for getting client IP address?</p>