1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00
Teknik/Utilities/RequestExtensions.cs

36 lines
954 B
C#
Raw Normal View History

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;
}
}
}