Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to Track where the user who is accessing your website is from Internet or from Intranet...

i need to hide/show some data on Default.aspx based on the logged in user...

if the user is from Intranet then some imp.data will be show...
if from the Internet data will be hidden.

thank you in advance...

quick help really appreciated...
Posted
Comments
Sinisa Hajnal 22-Oct-14 2:16am    
What have you tried? What are your ideas how it could be done?

Try this:
C#
var clientIP = System.Web.HttpContext.Current.Request.UserHostAddress;
bool isIntranetUser = clientIP.StartsWith("192.") || clientIP .StartsWith("172.") || clientIP.StartsWith("10.") || HttpRequest.Current.Request.IsLocal;
 
Share this answer
 
Read the IP address: Request.UserHostAddress[^] - if it starts with 192 then it's a local address (Check your DHCPcontroller for it's allocation list: most just use 192 addresses)
If it isn't local, it's internet!
 
Share this answer
 
Comments
Smart_Mohit 22-Oct-14 2:19am    
but the other employee which are working at other location(our branches outside india)
their machine ip is start with 10 not 192...how can i distinguish where the user is in intranet or internet ?

i think i need to check DHCP Allocation List.
OriginalGriff 22-Oct-14 2:50am    
DCHP won;t help you much, because once they leave your company remote site they "internal" IP address is hidden anyway, and you can only get the "public" internet IP.

If your remote sites use a static IP connection, then you can check for that (all users from the same site will have the same IP), but if it's dynamic then you will need to resort to logging in - which isn't such a stupid idea anyway! :laugh:

Log in is probably the best way to go: it allows remote workers (such as sales, support and work-from-home users) to access the full system as well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900