Jason Salas' WebLog

On-air and online: making people laugh, making people think, pissing people off

Sponsors

ASP.NET sites that kick ass

Pals with blogs

Podcasts I listen to

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=”64.45.21.235” 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:

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"];
else
           ispIPAddress = Request.ServerVariables["REMOTE_ADDR"];

Anyone have any ideas as to getting the IP or provider name?

Comments

Garrett Baker said:

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.
# April 6, 2004 8:57 PM

Jason Salas said:

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.
# April 6, 2004 11:42 PM

Michaels said:

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!

# April 17, 2013 5:42 PM