Demo entry 6648022

ip

   

Submitted by anonymous on Oct 22, 2017 at 15:13
Language: C#. Code size: 809 Bytes.

private void ShowIP()
    {
        //获取ip
        string userip = Request.ServerVariables["REMOTE_ADDR"];
        //从config读取ConnectionString
        string connectionString = ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString;
        //创建SqlConnection
        SqlConnection conn = new SqlConnection(connectionString);
        try
        {
            conn.Open();
            //插入ip到数据库
            string cmdText = "INSERT INTO IPTable(IP)VALUES("+userip+")";
            SqlCommand command = new SqlCommand(cmdText, conn);
        }
        catch (SqlException sqlex)
        {
            //显示错误信息
            Response.Write(sqlex.Message + "<br>");
        }
        finally
        {
            //关闭数据库链接
            conn.Close();
        }
    }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).