How do you get the IP address of a computer using ASP.net?

P

Progman

How do you get the IP address of a computer using ASP.net?


I tried Request.UserHostAddress and it does not work.

I get
Request for the permission of type
'System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

It should be possible, because many web site can show you your ip address.
 
S

sirfunusa

You did not read and apply what others have told you. You can never
rely on getting the ip address anyway. AOL users for example, always
will show the same IP, since they go through a proxy. What do you hope
to do with the IP? Hopefully nothing as naive as user personalization
or similar.

Create a one-line test.aspx with the following:

<% Response.Write (Request.ServerVariables("REMOTE_HOST")) %>
 
M

Mark Rae

What do you hope to do with the IP? Hopefully nothing as
naive as user personalization or similar.

Quite right! Anyone who believes that the the IP address supplied by any
browser to any server is even *remotely* accurate is seriously deluded...
 
P

Progman

"read and apply what others have told you"

sorry but nobody told me about anything to do except to try a line of code.
so nobody told me any instructions. you may be mixed up with another similar
thread.

txs for the input about the aol fact.

the "REMOTE_HOST" wont work.

I hope to identify the users computer so they dont create multiple accounts.
 
M

Mark Rae

I hope to identify the users computer so they dont create multiple
accounts.

LOL! Have you *really* not got it yet...? You can't rely on the IP address
to identify a computer. For one thing, lots of people are still using
dial-up, so their IP address is almost 100% *guaranteed* to be different
every time they connect to the internet - that's what the 'D' in DHCP
means...

Also, what's to stop someone from going to their neighbour's house and
creating another account from there? Or visiting an Internet cafe? Or...?
 
S

sirfunusa

Of course REMOTE_HOST will work. Did you try it? But YOU CANNOT get the
user's IP address reliably. End of story.
 
V

VickZaro

see my responses

Mark Rae said:
LOL! Have you *really* not got it yet...? You can't rely on the IP address
to identify a computer. For one thing, lots of people are still using
dial-up, so their IP address is almost 100% *guaranteed* to be different

but the proportion of people using cable increase and will be soon the
majority
every time they connect to the internet - that's what the 'D' in DHCP
means...

so I will put in the instructions, make sure your system is a same ip
address
simple...
Also, what's to stop someone from going to their neighbour's house and
creating another account from there? Or visiting an Internet cafe? Or...?

they will have to have a lot of friends to create many accounts. so this
will be the minority
 
M

Mark Rae

but the proportion of people using cable increase and will be soon the
majority

Even so, the vast majority of residential cable users are on DHCP too...
so I will put in the instructions, make sure your system is a same ip
address
simple...

ROTLFMAO! OK, then, explain to me just how you will instruct a home user on
dial-up to use the same IP address every time they connect...
 
S

sirfunusa

You CANNOT do this. You post here, and have received advice from the
experts. I, for one, wrote a book on the subject. Your path is ill
advised, and a very poor solution. I would never hire you. Use a
database, and store usernames and passwords..um...like MOST other
websites! There is a reason why they do this. Use the authentication
mechanisms built into .NET
 
W

webonomic

The original thread for this is here:
http://groups.google.ca/group/micro...r+using+ASP.net&rnum=2&hl=en#a73ff8a2b1d29038

Progman, in your first thread, people gave you the answer. I don't
want to offend you, but if you haven't figured it out, you shouldn't be
programming. Also, a quick and easy search on Google for "Asp.Net get
IP address" or something similar will reveal some good results to tell
you how to get the IP address. What you seem to want is someone to
write the code for you. Typically these groups provide paths to the
answer, you have to walk it yourself.

Now in your second thread you mention "I hope to identify the users
computer so they dont create multiple accounts. "

Hopefully peoples responses made sense. It is not programmatically
possible to stop people from creating multiple accounts. Because
person A may end up with person B's IP address, if you block IP address
from making another account, you just stopped person A from creating an
account because person B already made one.

You can store a cookie on a person's machine to track them, and then
check the cookie to see if they signed up already, but most people do
not allow cookies or just delete them.

You could search for Macromedia Flash stored objects which can mimic
cookies and it is harder to delete these. You'll have to talk to a
Macromedia user group for more info on that.

Alternatively, you can take a non programming approach and have people
sign up supply you with there home address and you can "snail mail"
them a password. (You know, the non-electronic way of mailing someone
a letter). But then some people have more then one house address they
could use, so you still can't 100% know if they already have an
account.

Using all of these methods together would be your best bet.
 
M

Mark Rae [MVP]

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top