How to detect Users's IP and then redirect to URL based on IP

Posted on 2008-11-11
Last Modified: 2012-08-14
Hi there, I need help to put this together. I want to create a basic web page that I will direct our clients to. When they get there they get a basic "You are being Redirected" and in the background I am retrieving their IP address and checking it again either a DB or file and then based on the result I am redirecting them to a SQL Report using that result as a parameter.

Now I am a complete novice to web development but have done some VB and some SQL so if some body could guide me I could probably get there.

How do I do this - I am sure it is a easy as for a web developer out there.

Question by:mickinoz2005
    LVL 32

    Expert Comment

    by:Daniel Wilson
            Dim strClientIP As String
     strClientIP = Request.UserHostAddress()
    LVL 5

    Author Comment

    Thanks for that but what about the query part to the SQL DB or text file.

    Any ideas on that.


    LVL 32

    Accepted Solution

    dim cmd as SqlCommand = new SqlCommand(new SqlConnection (MyConnStr), "Select RedirectPage from Redirects Where IP = @IP")
    dim P as SqlParameter = new SqlParameter("@IP", SqlDBType.nvarchar)
    P.Value = strClientIP
    cmd.Parameters.Add (P)

    dim dr as DataReader = cmd.ExecuteReader
    if then
    end if
    LVL 5

    Author Comment

    Hi there,

    When I add this code to visual studio I get SQLCommand is not defined, same with datareader.

    Can you assist with this please.


    LVL 5

    Author Closing Comment

    As a complete novice the solution left a lot for me to still resolve which put me really back where I started. The IP part was complete and worked perfectly for not the DB part.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now