This code will get the client side IP address on page laod event and store in database.
- //Javascript code
- <script type="text/javascript" src="http://l2.io/ip.js?var=myip"></script>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript" language="javascript">
- $(document).ready(function () {
- var queryString = window.location.search;
- if(queryString == "")
- {
- alert("Data inserted");
- window.location.href = "http://localhost:2305/WebSite66/Default.aspx?ip="+myip;
- return false;
- }
- });
- </script>
-
- protected void Page_Load(object sender, EventArgs e)
- {
- if (Request.QueryString["ip"] != "" && Request.QueryString["ip"] != null)
- {
- string ip = Request.QueryString["ip"].ToString();
- if (con != null && con.State == ConnectionState.Closed)
- {
- con.Open();
- }
- //Insert in database code
-
- if (con != null && con.State == ConnectionState.Open)
- {
- con.Close();
- }
- }
- }