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 595B

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