Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to get the client ip address who login his system in asp.net with c#

how to get the client ip address who login his system in asp.net with c#

Scheduled Pinned Locked Moved ASP.NET
csharpcssasp-netdatabasetutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    developerit
    wrote on last edited by
    #1

    hi iam using asp.net with c# in my application when user login successfully,then in the next page based on the client database i have to display data in a grid view , so how to give connection string in asp.net with c# can you correct my code which helps me

    protected void Page_Load(object sender, EventArgs e)
    {

        string strHostName = System.Net.Dns.GetHostName();
        string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
    
        string strcon = "Data Source=";
        strcon += clientIPAddress+";" + "Initial Catalog=POS;Trusted\_connection=true";
    
        
        SqlConnection con = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("select \* from AllTransactions where BranchKey=" + Convert.ToInt32(Session\["BranchKey"\]) + "", con);
    
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "tt");
        GridView1.DataSource = ds.Tables\["tt"\];
        GridView1.DataBind();
    }
    

    the data is displaying in my system but when client logins it is showing no record, can you correct my code

    L T 2 Replies Last reply
    0
    • D developerit

      hi iam using asp.net with c# in my application when user login successfully,then in the next page based on the client database i have to display data in a grid view , so how to give connection string in asp.net with c# can you correct my code which helps me

      protected void Page_Load(object sender, EventArgs e)
      {

          string strHostName = System.Net.Dns.GetHostName();
          string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
      
          string strcon = "Data Source=";
          strcon += clientIPAddress+";" + "Initial Catalog=POS;Trusted\_connection=true";
      
          
          SqlConnection con = new SqlConnection(strcon);
          SqlCommand cmd = new SqlCommand("select \* from AllTransactions where BranchKey=" + Convert.ToInt32(Session\["BranchKey"\]) + "", con);
      
          SqlDataAdapter da = new SqlDataAdapter(cmd);
          DataSet ds = new DataSet();
          da.Fill(ds, "tt");
          GridView1.DataSource = ds.Tables\["tt"\];
          GridView1.DataBind();
      }
      

      the data is displaying in my system but when client logins it is showing no record, can you correct my code

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I am not able to understand why and how you need to access client side database. But for getting client IP Use this..

      Request.ServerVariables("REMOTE_ADDR")

      HTH

      Jinal Desai - LIVE Experience is mother of sage....

      1 Reply Last reply
      0
      • D developerit

        hi iam using asp.net with c# in my application when user login successfully,then in the next page based on the client database i have to display data in a grid view , so how to give connection string in asp.net with c# can you correct my code which helps me

        protected void Page_Load(object sender, EventArgs e)
        {

            string strHostName = System.Net.Dns.GetHostName();
            string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
        
            string strcon = "Data Source=";
            strcon += clientIPAddress+";" + "Initial Catalog=POS;Trusted\_connection=true";
        
            
            SqlConnection con = new SqlConnection(strcon);
            SqlCommand cmd = new SqlCommand("select \* from AllTransactions where BranchKey=" + Convert.ToInt32(Session\["BranchKey"\]) + "", con);
        
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "tt");
            GridView1.DataSource = ds.Tables\["tt"\];
            GridView1.DataBind();
        }
        

        the data is displaying in my system but when client logins it is showing no record, can you correct my code

        T Offline
        T Offline
        Tej Aj
        wrote on last edited by
        #3

        check thi post http://opexsolution.com/forum/viewtopic.php?f=15&t=53&p=159#p159[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups