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
sadlermdAsked:
Who is Participating?
 
Paul MacDonaldDirector, Information SystemsCommented:
I'd just do something like;

If Request.ServerVariables("REMOTE_ADDR").ToString.StartsWith("192.168.0") Then
...
End If

Where 192.168.0 is the network number for the internal network.
0
 
sammySeltzerCommented:
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

...

0
 
sadlermdAuthor Commented:
works...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.