Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ASP.net Test if user comes from Local Network

Tags:

c#

asp.net

local

I want to use C#/ASP.net to find out whether the user browsing the website is on the same network so that certain links are only displayed while in the office (to those who have access to them).

Anyone accessing from within the office will be doing so by going to it's local IP address (i.e. 192.168.x.x) whereas external users will be browsing to the public domain name.

All I need is some way to differentiate between the two types of user.

like image 486
ForbesLindesay Avatar asked Sep 17 '25 06:09

ForbesLindesay


1 Answers

if (Request.UserHostAddress.StartsWith("192.168"))
{
    //localuser
}
like image 92
Simon Hazelton Avatar answered Sep 19 '25 19:09

Simon Hazelton