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=”” value=””/>
<add key=”” value=””/>
<add key=”” value=””/>

…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:

string ispIPAddress;

// 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?


  • You could look up the user's ip address in whois to find the owner of the IP block.

    This would provide the company information. Usually this information includes email addresses and URLs. Of course, this is more complex than using a web.config file.

  • Hi Garrett,

    Interesting tip...although I'm pretty sure the default homepage URL for mobile splash pages wouldn't be available from within a WHOIS query.

  • Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is important and everything.
    Nevertheless think about if you added some great images or video clips to give your posts more,
    "pop"! Your content is excellent but with pics and video clips, this
    blog could certainly be one of the most beneficial
    in its field. Very good blog!

Comments have been disabled for this content.