How do I know the IP of logging user?

Last post 05-17-2008 5:58 AM by deepakgoyal86. 14 replies.

Sort Posts:

  • How do I know the IP of logging user?

    05-15-2008, 8:36 AM

    hi there

    I am writting a method for system log..

    I have to record the act of user did ... one of the colums is "IP"

    but how do I get the IP from the logging user?

    can you please help? thank you very much

  • Re: How do I know the IP of logging user?

    05-15-2008, 9:03 AM
    Answer
    • Loading...
    • Curt_C
    • Joined on 07-23-2003, 4:27 PM
    • Stevens Point, WI - USA
    • Posts 4,015
    • Moderator

    look at the Request object... you should be able to get all you need from there.

    But note... you wont necessarity get the IP of the user, you may get a Firewall, NAT box, Router, etc.... from somewhere in between

  • Re: How do I know the IP of logging user?

    05-15-2008, 9:05 AM
    Answer
    • Loading...
    • fimine
    • Joined on 01-17-2008, 2:01 PM
    • Montreal QC Canada
    • Posts 256

     System.Web.HttpContext.Current.Request.UserHostAddress 

    Alexei Fimine
    _____________
    Don't forget to mark this post as "Answer" if it indeed answered.
  • Re: How do I know the IP of logging user?

    05-15-2008, 9:24 AM
    Answer
    • Loading...
    • rbansal44
    • Joined on 12-11-2007, 10:09 AM
    • Posts 100

    hi,

    string s= Request.ServerVariables["Remote_Host"];

    thanks,

    rajiv

  • Re: How do I know the IP of logging user?

    05-15-2008, 9:34 AM

    hi, thank you I'm going to give it a try..

    but can you explian more about you must metioned?

    "you may get a Firewall, NAT box, Router, etc.... from somewhere in between"

    what does it mean? and if I mee the problem how to solve?

    thank you very much

  • Re: How do I know the IP of logging user?

    05-15-2008, 9:44 AM
    Answer
    • Loading...
    • fimine
    • Joined on 01-17-2008, 2:01 PM
    • Montreal QC Canada
    • Posts 256

    Many inteternet users access the web trough an intermediary. i. e. there can be a number of different users using the same IP address  simultaneously (this is very common for home networks and even some ISPs) thus you cannot rely upon IP to uniquely identify your users, unless you are in a strictly managed environment and you know for a fact that your users have unique IPs.  

    Alexei Fimine
    _____________
    Don't forget to mark this post as "Answer" if it indeed answered.
  • Re: How do I know the IP of logging user?

    05-15-2008, 10:39 AM

    so... to keep ID is not a good idea??

    do you have other sugesstion for me?

     

    thank you

  • Re: How do I know the IP of logging user?

    05-15-2008, 11:18 AM
    • Loading...
    • Curt_C
    • Joined on 07-23-2003, 4:27 PM
    • Stevens Point, WI - USA
    • Posts 4,015
    • Moderator

    IP tracking isnt really a usefull item... Whole corporations worth of users may show up as a Single IP...

    The best way to track users, is to track the users... make them signup/register and then track their userIDs. Beyond that just group all the rest as "unregistered users". This would be crawlers, anon users, bots, etc....

  • Re: How do I know the IP of logging user?

    05-15-2008, 11:24 AM
    • Loading...
    • fimine
    • Joined on 01-17-2008, 2:01 PM
    • Montreal QC Canada
    • Posts 256

    It all depends on what you are trying to achieve. You can either use login/logout with your very own user management system. Or you can use http Session.  

    Alexei Fimine
    _____________
    Don't forget to mark this post as "Answer" if it indeed answered.
  • Re: How do I know the IP of logging user?

    05-15-2008, 11:33 AM

    hm... may I ask extra quesion?

    if I want to keep the login ID and name of logging user

    how do I know who are loging?

    like user will login from main.aspx

    when they are doing something in A.page or B.page

    how do I know the act person's ID and name?

    thank you again

  • Re: How do I know the IP of logging user?

    05-15-2008, 11:36 AM
    • Loading...
    • fimine
    • Joined on 01-17-2008, 2:01 PM
    • Montreal QC Canada
    • Posts 256

     There is a whole set of login controls in VS2005-2008 to help you with that. At the basic level, create a class whose object will store user info once the user is logged in and keep an instance of this class in a session variable throughout your pages.

    Alexei Fimine
    _____________
    Don't forget to mark this post as "Answer" if it indeed answered.
  • Re: How do I know the IP of logging user?

    05-15-2008, 12:04 PM

    can you please give me a example for creat a class for store user info?

    I also wondering is it ok if I use Session to pass the loging ID for each pages?

     

    thank you

  • Re: How do I know the IP of logging user?

    05-15-2008, 4:29 PM
    • Loading...
    • fimine
    • Joined on 01-17-2008, 2:01 PM
    • Montreal QC Canada
    • Posts 256

    http://www.codeproject.com/KB/web-security/formsroleauth.aspx 

    Alexei Fimine
    _____________
    Don't forget to mark this post as "Answer" if it indeed answered.
  • Re: How do I know the IP of logging user?

    05-17-2008, 4:55 AM
    Answer
    • Loading...
    • Talib_dotnet
    • Joined on 01-31-2008, 11:02 AM
    • Riyadh , K.S.A
    • Posts 283

    Hi,

    Try this code  for detecting  User's  IP. 

     string strHostName = System.Net.Dns.GetHostName();
    string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();


    Now set the value of clientIPAddress to either a Textbox or Label or any control as per your requirement.

    Hope  this  helps  you..... 

     

    Click "Mark As Answer" if it helped you.


    TALIB ALI KHAN
    MCTS
    Welcome to TALIB's World



  • Re: How do I know the IP of logging user?

    05-17-2008, 5:58 AM
    keepfatinmind:

    can you please give me a example for creat a class for store user info?

    I also wondering is it ok if I use Session to pass the loging ID for each pages?

     

    thank you

    When a authorised user loggs in, a session is created. This session is used for discriminating beetween authenticated and non authenticated users on every page. On the page load, this session check is done. If the session check is failed, you redirect the user to home page or a similar page using Responce.Redirect() method. This keeps non authenticated users to keep away from sensitive data. If you are using sessions, you do not pass session information to every page, that information exists, you just retrieve this information when needed, and it is absolutely safe.
    Example:
    1) Create a session:
    Session["id"] = rd.GetString(0); // Where rd.getstring(0) retrieves your user id from database.
    2) Evaluate a session for authorized data access:
          if (Session["status"] == null) // Session remains null if user directly types url of the page without logging in first.
              {
                  Response.Redirect("default.aspx");
              }
          else
              {
          if (Session["status"].ToString() != "manager") // to check if logged in user has proper rights or not. This section can be modified in many ways.
              {
                  Response.Redirect("default.aspx");
              }
          }

    It is very important to create sessions and authenticate them for a website.

    Regarding your IP tracing, you must know that today most of ISP provides dynamic IP to their subscribers. IP changes everytime the user reconnects to internet. You will not be able to trace your users this way. Using Sessions and making an entry in DB @ time of login or logout of User Id is the best idea!!
Page 1 of 1 (15 items)