using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Net; using System.Text; namespace Teknik.Utilities { public static class RequestExtensions { public static bool IsLocal(this HttpRequest req) { var connection = req.HttpContext.Connection; if (connection.RemoteIpAddress.Equals(connection.LocalIpAddress)) { return true; } if (IPAddress.IsLoopback(connection.RemoteIpAddress)) { return true; } return false; } public static bool IsAjaxRequest(this HttpRequest request) { if (request == null) throw new ArgumentNullException("request"); if (request.Headers != null) return request.Headers["X-Requested-With"] == "XMLHttpRequest"; return false; } } }