user1430372
user1430372

Reputation: 41

Accessing information from Client in ASP.Net

I have an ASP.Net website where I want to be able to know below things about the person who is browsing my website.

  1. logged In user name of OS.
  2. Exact OS in (Type of the Os - Windos, Mac etc.: Version of OS).
  3. Mac Address
  4. IP Address of the client mechine.

my website is a higly secure one and I can fource users to isntall activex and/or some applet if that is required to access the website.

Pleae help me the best way of doing so.

Upvotes: 0

Views: 1260

Answers (1)

balexandre
balexandre

Reputation: 75113

1 - logged In user name of OS

This is only available if you are using WIndows Forms as your Authentication method, if you are using Forms, you can easily get it's name/user by it's logged in account

2 - Exact OS in (Type of the Os - Windos, Mac etc.: Version of OS).

We call this Browser Agent and you can get it by using in javascript:

navigator.userAgent

3 - Mac Address

You can only get the Mac Address of your own server, the one where you have the website hosted, and you can get as many as the network devices that server has, remember that Mac Address are not unique!

4 - IP Address of the client machine.

There is no way to get this with only javascript, you need to use your programming language for, you should use this to get the real IP Address:

string ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if(ip == "") { 
    ip = Request.ServerVariables["REMOTE_ADDR"]; 
}

All together, and using jQuery to be simple:

<%
    string ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if(ip == "") { ip = Request.ServerVariables["REMOTE_ADDR"]; }
%>
<script type="text/javascript">

  $(function() {

    var ipAddress = '<% = ip %>',
        browser = navigator.userAgent,
        username = <% = Session["username"] %>;

    // now send the data back to your server, if using jQuery, just do:
    $.get("/login-user.aspx", { 
            ip: ipAddress, 
             browser: browser, 
             user: username 
          }, function(data) {
             // use this if you return anything as a response             
          });
   });    
</script>

You then can use http://UserAgentString.com/ API to parse your User Agents strings, or use the navigator object to get what you want from the browser (or any 3rd party libraries)...

Upvotes: 1

Related Questions