views:

97

answers:

2

If a user navigates to my webpage how can I programmatically determine they are accessing my page from within the Intranet? (Not interested in NTLM or Windows forms authentication. Need a programmatic method.)

+1  A: 

You can read the IP address out of the Http request and then check that address against the range that is the local intranet.

Shiraz Bhaiji
Is there a method of checking using the domain name?
Checking the domain name checks who he is and that he is authenticated, not where he is.
Shiraz Bhaiji
A: 

Consider these two snippets for obtaining the client's IP address:

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]

or

//this is a wrapper for REMOTE_ADDR:
HttpContext.Current.Request.UserHostAddress

If it falls within 10.x.x.x, or 192.168.x.x, then you know your visit is from the inside.

Otherwise, you could check the URL for a known good server name or alias:

HttpContext.Current.Request.ServerVariables["SERVER_NAME"]
p.campbell