?
Solved

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

Posted on 2008-11-11
5
Medium Priority
?
257 Views
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.
Cheers

Michael
0
Comment
Question by:mickinoz2005
  • 3
  • 2
5 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22935018
from http://bytes.com/forum/thread439176.html
        Dim strClientIP As String
 strClientIP = Request.UserHostAddress()
 Response.Write(strClientIP)
 
0
 
LVL 5

Author Comment

by:mickinoz2005
ID: 22935314
Thanks for that but what about the query part to the SQL DB or text file.

Any ideas on that.

Cheers

0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 1000 total points
ID: 22939417
dim cmd as SqlCommand = new SqlCommand(new SqlConnection (MyConnStr), "Select RedirectPage from Redirects Where IP = @IP")
cmd.Connection.Open()
dim P as SqlParameter = new SqlParameter("@IP", SqlDBType.nvarchar)
P.Value = strClientIP
cmd.Parameters.Add (P)

dim dr as DataReader = cmd.ExecuteReader
if dr.read then
  Response.Redirect(dr.GetString(0))
end if
0
 
LVL 5

Author Comment

by:mickinoz2005
ID: 23028771
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.

Thanks

Michael
0
 
LVL 5

Author Closing Comment

by:mickinoz2005
ID: 31515759
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.
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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 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