Adam Bickels
Adam Bickels

Reputation: 471

Get Unique identifier from client ASP.Net c#

Can i get from a client who visits my site some unique key like MAC Address ? i'm trying to get this id to store in the db so client can't access it anymore if it already visits the page.

Upvotes: 1

Views: 5895

Answers (3)

Igor Ševo
Igor Ševo

Reputation: 5515

To get the user's IP address, you can use what others have suggested. However, you cannot obtain a user's MAC address unless they are directly connected to your router.

If you want to uniquely identify your user, you should try to identify them by a combination of IP, OS and some other specific data. However, this will still not be entirely reliable.

If you allow registration on your website, then you could identify users by their e-mail addresses.

There is a question on StackOverflow that seems to be about the same thing: How do I uniquely identify computers visiting my web site?. An answer there suggests the usage of cookies. You might want to check out the following article: Beginner's Guide to ASP.NET Cookies.

Upvotes: 2

Sajad Karuthedath
Sajad Karuthedath

Reputation: 15767

You can't get the MAC Address of your client

to get the IP address use

string ipaddress;
ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipaddress == "" || ipaddress == null)
    ipaddress = Request.ServerVariables["REMOTE_ADDR"];

http://www.aspsnippets.com/Articles/How-to-get-IP-Address-of-Visitors-Machine-in-ASP.Net.aspx

Upvotes: 1

Dgan
Dgan

Reputation: 10285

Gives Random Hex Number Each Time New One

string newID= Guid.NewGuid().ToString();

Upvotes: 0

Related Questions