I have a .net mvc application deployed on my server. The application requires authentication of user based on his location, i.e, user should be allowed to login to the application only if he is accessing it from a network with gateway say '192.168.x.y' and not from any other network. When I try to get the gateway address in the application, I am always getting the gateway of the server in which my application is deployed. How can I get the gateway address of the system from which the user is trying to access the application?
This is what I used
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses;
if (addresses.Count > 0)
{
return addresses[0].Address.ToString();
}
}