Link to home
Start Free TrialLog in
Avatar of sadlermd
sadlermd

asked on

How to correctly recognize intranet users from internet users (IIS 7)...

Using: C#, .NetFramework 3.5 and 4, IIS 7

I am trying to determine if the user who is navigating to our site is on our intranet.

Here is what I have, and it works when I test it on my development pc - just not 100% sure this is production ready:

string userTryingToLoginToMyWebApp = Request.UserHostAddress;
string serverHostingMyWebApp = Request.ServerVariables["LOCAL_ADDR"];

if (userTryingToLoginToMyWebApp == serverHostingMyWebApp) { // "intranet user..."; }


Thanks in advance,

Rick
ASKER CERTIFIED SOLUTION
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
for us at our prganization, our intranet IP ranges are:

10.0.0.0 … 10.255.255.255
172.16.0.0 … 172.31.255.255
192.168.0.0 ....

So, you will have to put those into consideration.

You have may have to do something like:

If Request.ServerVariables("REMOTE_ADDR").ToString.StartsWith("192.168.0")
OR
Request.ServerVariables("REMOTE_ADDR").ToString.StartsWith("172.16.0.0")
OR
Request.ServerVariables("REMOTE_ADDR").ToString.StartsWith("10.0.0.0") Then

...

Avatar of sadlermd
sadlermd

ASKER

works...