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>");
}
{
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>");
}
解决方案 »
- 关于Response.Redirect的问题
- 求教一个关于imagebutton控件的问题
- 动态生成的Textbox和lable,如何布局样式
- asp.net生成静态页面如何做分页?
- 为什么总要这样?
- 上海范围内有支持ASP.NET 2.0的空间吗?
- 怎样请求一个IP地址并返回到原程序位置?
- 怎样在.ASPX文件里设置窗口的属性?
- 请教一个SQL语句的写法
- 大家帮我找找这个错误类型,快郁闷死了!!!现在时间凌晨5点了||“LinkButton”的控件“lbtFirst”必须放在具有 runat=server 的窗体标
- 在代码中明明有ItemCommand事件,为什么运行时说不包含ItemCommand事件
- 如何建立一个站点级的公用的数据库连接
具体参数我忘了,网上有
request.serverviaribles["REMOTE_ADDR"]
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;
}
}
{
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;
}
}
{
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);
}