足力健后端,使用.netcore版本,合并1个项目使用

IPHelper.cs 520B

12345678910111213141516171819202122
  1. using Microsoft.AspNetCore.Http;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace System.Common
  7. {
  8. public static class IPHelper
  9. {
  10. public static string GetIp(this HttpContext context)
  11. {
  12. var ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
  13. if (string.IsNullOrEmpty(ip))
  14. {
  15. ip = context.Connection.RemoteIpAddress.ToString();
  16. }
  17. return ip;
  18. }
  19. }
  20. }