protected void Button1_Click(object sender, EventArgs e)
    {
        string Edittext = WebEditor1.Text;        string tempnewstitle = Request.Form["newstitle"].Trim();
        string temppublishertel = Request.Form["publishertel"].Trim();
        string temppublisher = Request.Form["publisher"].Trim();
        mySocut.ExecuteSql("Insert Into liyang(newstitle,userphone,username,newstext,publishtime) Values ('" + tempnewstitle + "','" + temppublishertel + "','" + temppublisher + "','" + Edittext + "','" + DateTime.Now + "')  ");
        Response.Write("<script>alert('新增成功!');location.href='rep.aspx';</script>");
    }

解决方案 »

  1.   

    用request.serverviaribles["..."]
    具体参数我忘了,网上有
      

  2.   

    Request.UserHostAddress
    request.serverviaribles["REMOTE_ADDR"]
      

  3.   

    给你最详细的
    public static string IP
            {
                get
                {
                    string userIP;
                     HttpRequest Request = HttpContext.Current.Request;
                    
                    // 如果使用代理,获取真实IP
                    if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != "")
                        userIP = Request.ServerVariables["REMOTE_ADDR"];
                    else
                        userIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    if (userIP == null || userIP == "")
                        userIP = Request.UserHostAddress;
                    return userIP;
                }
            }
      

  4.   

    public static string IPAddressAll
            {
                get
                {
                    string ip = HttpContext.Current.Request.UserHostAddress;
                    string agentip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    if (!string.IsNullOrEmpty(agentip))
                    {
                        //有代理                    if (agentip.IndexOf(".") == -1)
                            agentip = null;
                        if (agentip != null)
                        {
                            if (agentip.IndexOf("unknow") != -1)
                                agentip = agentip.Replace("unknow", string.Empty);                        string[] temparyip = agentip.Replace(" ", string.Empty).Replace("'", string.Empty).Split(new char[] { ',', ';' });
                            //过滤代理格式中的非IP和内网IP
                            for (int i = 0; i < temparyip.Length; i++)
                            {
                                if (temparyip[i] != string.Empty && IsIPAddress(temparyip[i])
                                            && temparyip[i].Substring(0, 3) != "10."
                                            && temparyip[i].Substring(0, 7) != "192.168"
                                            && temparyip[i].Substring(0, 7) != "172.16.")
                                {
                                    ip += "," + temparyip[i];
                                }
                            }
                        }
                    }
                    else
                    {
                        agentip = null;
                    }                return ip;
                }
            }
      

  5.   

    public static string GetUserIpAddress(HttpContext context)
            {
                string result = String.Empty;
                if (context == null)
                    return result;            result = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (result != null && result != String.Empty)
                {
                    //可能有代理 
                    if (result.IndexOf(".") == -1)    //没有“.”肯定是非IPv4格式 
                        result = null;
                    else
                    {
                        if (result.IndexOf(",") != -1)
                        {
                            //有“,”,估计多个代理。取第一个不是内网的IP。 
                            result = result.Replace(" ", "").Replace("'", "");
                            string[] temparyip = result.Split(",;".ToCharArray());
                            for (int i = 0; i < temparyip.Length; i++)
                            {
                                if (IsIPAddress(temparyip[i])
                                    && temparyip[i].Substring(0, 3) != "10."
                                    && temparyip[i].Substring(0, 7) != "192.168"
                                    && temparyip[i].Substring(0, 7) != "172.16.")
                                {
                                    return temparyip[i];    //找到不是内网的地址 
                                }
                            }
                        }
                        else if (IsIPAddress(result)) //代理即是IP格式 
                            return result;
                        else
                            result = null;    //代理中的内容 非IP,取IP 
                    }            }            //比较通用的获得IP的方法
                //string IpAddress = (context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null && context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != String.Empty) ? context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] : HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                if (null == result || result == String.Empty)
                    result = context.Request.ServerVariables["REMOTE_ADDR"];            if (result == null || result == String.Empty)
                    result = context.Request.UserHostAddress;            return result;
            }        /// <summary>
            /// 判断一个字符串是否符合IP格式
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static bool IsIPAddress(string str)
            {
                if (str == null || str == string.Empty || str.Length < 7 || str.Length > 15) return false;            string regformat = @"^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$";            Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
                return regex.IsMatch(str);
            }