My project is a web-application that is to serve as a company Landing Page with a logo and quick links.
I would like to add extra links to LAN-based webpages for users who are in my local LAN, but hide those links if the page is served outside the local LAN.
I know how to hide and show things How can I tell whether the page is served in the LAN or outside the LAN?
This is the only thing I've come up with so far, but I'm not sure it will work. (strings.left() is one of my own function that fetches the first x characters from the left of a string)
protected void Page_Load(object sender, EventArgs e) {
String thisipaddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
if (thisipaddress == "127.0.0.1" || strings.left(thisipaddress,7)=="192.168"){
hiddenarea.Visible = true;
} else {
hiddenarea.Visible = false;
}
}
I guess what I need to know is, with my current code, if a user in another LAN access my page, will my code detect their internal ipaddress or their external one?
This does the trick. It detects external ip address from outside the lan and internal ipaddress from inside the lan. And if the page is accessed from an external LAN with a matching ipaddress, it still returns the external one.
protected void Page_Load(object sender, EventArgs e) {
String thisipaddress = Request.UserHostAddress; <-----THIS
if (thisipaddress == "127.0.0.1" || strings.left(thisipaddress,7)=="192.168"){
hiddenarea.Visible = true;
} else {
hiddenarea.Visible = false;
}
}