[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET web page to detect users IP, then redirect to another web page based on that

Posted on 2005-04-17
5
Medium Priority
?
381 Views
Last Modified: 2010-04-07
Hello,

I'm after the code/page in ASP.NET/ASP for a page which get the visiting users IP and if it falls within one IP range the user is redirected to a URL, if it falls outside of this IP range then the user is forwarded to a different URL.

Get Users IP

Is the Users IP in the range e.g. 192.168.0.1 - 192.168.0.32  (or by subnet)

If yes, redirect to http://server1.domain.com

else

redirect to http://server2.domain.com

Any help with this will be appreciated, i'm useless at programming and need all the help i can get ASAP.

Thanks!
0
Comment
Question by:JamesRHart
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 2000 total points
ID: 13800638
Private Sub Page_Load(ByVal sender As Object,ByVal e As EventArgs) Handles MyBase.Load
      Dim parts As String() = Request.UserHostAddress.Split(".".ToCharArray)
      Dim ip As Integer() = New Integer() {CInt(parts(0)), CInt(parts(1)), CInt(parts(2)), CInt(parts(3))}
      If p(0) = 192 AndAlso p(1) = 168 AndAlso p(2) = 0 AndAlso p(3) > 0 AndAlso p(3) < 33 Then
            Response.Redirect("http://server1.domain.com",True)
      Else
            Response.Redirect("http://server2.domain.com",True)
      End If
End Sub

0
 

Author Comment

by:JamesRHart
ID: 13800716
Hi there,

Thanks for the reponse!

I've put  it all in a apge and it works fine (i think you mean ip instead of p, so i changed that bit).

If you have a chance can you also help me with something else,

I have another question on ee, basically i want to connect to a sql server, run a stored procedure, get the result... do the same on a another server.  Then compare the results and whichever has the lowest value, redirect to that website.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21383881.html#13790310
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13800723
lol yep typo

amended for completeness
======
      
Private Sub Page_Load(ByVal sender As Object,ByVal e As EventArgs) Handles MyBase.Load
     Dim parts As String() = Request.UserHostAddress.Split(".".ToCharArray)
     Dim p As Integer() = New Integer() {CInt(parts(0)), CInt(parts(1)), CInt(parts(2)), CInt(parts(3))}
     If p(0) = 192 AndAlso p(1) = 168 AndAlso p(2) = 0 AndAlso p(3) > 0 AndAlso p(3) < 33 Then
          Response.Redirect("http://server1.domain.com",True)
     Else
          Response.Redirect("http://server2.domain.com",True)
     End If
End Sub
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13800729
am looking at your mentioned question now...
0
 

Author Comment

by:JamesRHart
ID: 13800741
Thanks, just read your profile... I am one of those users who doesnt have a lot of knowledge in coding (I'm a network admin/engineer), but i'm willing to put the effort in (just haven't got much coding knowledge to back it up (other than good old VB6)).  EE isn't the first place i went to try for a solution.   I did spend a lot of time with books and on the net, it's just very frustrating when you hit a brick wall and can't figure out why things aren't working.

Would appreciate any help!

Thanks again!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month19 days, 6 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question