The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RequestExtensions.cs 954B

1234567891011121314151617181920212223242526272829303132333435
  1. using Microsoft.AspNetCore.Http;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Net;
  5. using System.Text;
  6. namespace Teknik.Utilities
  7. {
  8. public static class RequestExtensions
  9. {
  10. public static bool IsLocal(this HttpRequest req)
  11. {
  12. var connection = req.HttpContext.Connection;
  13. if (connection.RemoteIpAddress.Equals(connection.LocalIpAddress))
  14. {
  15. return true;
  16. }
  17. if (IPAddress.IsLoopback(connection.RemoteIpAddress))
  18. {
  19. return true;
  20. }
  21. return false;
  22. }
  23. public static bool IsAjaxRequest(this HttpRequest request)
  24. {
  25. if (request == null)
  26. throw new ArgumentNullException("request");
  27. if (request.Headers != null)
  28. return request.Headers["X-Requested-With"] == "XMLHttpRequest";
  29. return false;
  30. }
  31. }
  32. }