本人新手,突然碰到string的问题不知道如何获取值,代码如下,
不带参数的string GetIP(),我调用它的value'"+GetIP()+"' 是OK的。
但是碰到带有参数的我如何获取string GetstringIpAddress(string strIP)的值,
求解答啊,红色标记处为问题所在。
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;
using System.IO;
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
public SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
string sConnectionString = @"server=XXXXXX;database=XXXXXX;user id=sa;password=XXXXXX;";
string sSql = "insert into IP(ip,DateTime,area) values('" + GetIP() + "',getdate(),'"+GetstringIpAddress+"')";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = sConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sSql;
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
public string GetIP()
{
string result = String.Empty;
result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(result))
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (string.IsNullOrEmpty(result))
{
result = HttpContext.Current.Request.UserHostAddress;
}
if (string.IsNullOrEmpty(result))
{
return "127.0.0.1";
}
return result;
}
public static string GetstringIpAddress(string strIP)//strIP为IP
{
string GetIP = strIP;