Creating a provider-specific [HOME] link in ASP.NET mobile apps
I’m working on a very fun project, only because it’s confusing the hell out of me. Essentially, I want to create a mobile Link whose NavigateUrl property would be dynamically assigned, based on the ISP or other service provider they use. So, I’d need to figure out a way to get the IP (or a range) of the calling client. This results in the user clicking on the link and being returned to their ISP’s homepage.
I’m also trying to do something that can pull the value of MSIE’s “Home” value, so that they can return to the user-defined homepage as specified in the browser settings.
Essentially, here’s what I’m doing in web.config:
<add key=”192.168.0.1” value=”http://foo.com”/>
<add key=”127.0.0.1” value=”http://bar.com”/>
<add key=”184.108.40.206” value=”http://foobar-corp.com”/>
…then within my ASP.NET pages:
Link l = new Link();
l.Text = “Return home”;
l.NavigateUrl = // somehow get the IP of the ISP they use and insert the destination URL from web.config
This helpr method seems to work, although it's hacky:
// if the client is accessing the resource through a proxy server, the proxy IP will be in "HTTP_X_FORWARDED_FOR"
// "HTTP_CLIENT_IP" is rarely used
if(Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null || Request.ServerVariables["HTTP_CLIENT_IP"] != null)
ispIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
ispIPAddress = Request.ServerVariables["REMOTE_ADDR"];
Anyone have any ideas as to getting the IP or provider name?