The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HttpRequestExtensions.cs 571B

123456789101112131415161718192021
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Http;
  6. using System.Web;
  7. namespace Teknik.Utilities
  8. {
  9. public static class HttpRequestExtensions
  10. {
  11. public static string GetClientIpAddress(this HttpRequestMessage request)
  12. {
  13. if (request.Properties.ContainsKey("MS_HttpContext"))
  14. {
  15. return IPAddress.Parse(((HttpContextBase)request.Properties["MS_HttpContext"]).Request.UserHostAddress).ToString();
  16. }
  17. return null;
  18. }
  19. }
  20. }