为什么在load的时候在mysql里面插入数据错误呢?
protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack)
{
#region 根据条件显示验证码
if (Request.Cookies["Lang"] == null || Request.Cookies["Lang"].Value == "")
{
foreach (ListItem li in DropDownList.Items)
{
if (li.Value == "")
Lang = "zh-cn";//给个默认的
}
}
else
{
foreach (ListItem li in DropDownList.Items)
{
if (li.Value.ToLower() == Request.Cookies["Lang"].Value)
li.Selected = true;
}
}
if ((Session["pwdErrorCount"] != null) && (Session["pwdErrorCount"].ToString() != ""))
{
int PassErroeCount = Convert.ToInt32(Session["pwdErrorCount"]);
if (PassErroeCount >= 3)
{
this.UpdatePanel2.Visible = true;
}
else
{
this.UpdatePanel2.Visible = false;
}
}
else
{
this.UpdatePanel2.Visible = false;
}
#endregion
#region 如果获取到的Cookie账号和密码没有错误,就直接进入后台
if (Request.Cookies["VSLoginUsername"] != null && Request.Cookies["VSLoginPassword"] != null && Request.Cookies["VSLoginUsername"].Value != "" && Request.Cookies["VSLoginPassword"].Value != "")
{
wxh.BLL.UsersBLL bllUser = new wxh.BLL.UsersBLL();
string username = Request.Cookies["VSLoginUsername"].Value;
string password = wxh.Common.Simple.Decrypt(Request.Cookies["VSLoginPassword"].Value, 12345);
wxh.Model.UsersInfo mod = bllUser.GetModel(username);
if (mod.pwd.Equals(wxh.Common.MD5.Encrypt(password, 32)))
{
Response.Redirect("Main/Main.aspx");
}
else
{
if (Request.Cookies["Lang"].Value.ToLower() == "zh-cn")
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('Cookie记录账号有误!');</script>");
}
if (Request.Cookies["Lang"].Value.ToLower() == "zh-tw")
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('Cookie記錄賬號有誤!');</script>");
}
}
}
#endregion
//显示第三方登录图标
litOtherLoginInfo.Text = OAuth2.UI.GetHtml();
}
//获取当前的授权类型,如果成功,则会缓存到Session中。
OAuth2.OAuth2Base ob = OAuth2.OAuth2Factory.Current;
//说明用户点击了授权,并跳回登陆界面来
if (ob != null)
{
string account = string.Empty;
//检测是否授权成功
if (ob.Authorize(out account))
{
Session["token"] = ob.token;//这里保存的是token的值;
Session["openid"]= ob.openID;//这里是保存的是用户的Openid;
Session["niname"]= ob.nickName;//这里保存的是用户昵称;
//Response.Write("<script language=javascript>alert('" + token + "+" + openid + "+"+ niname +"+"+ head +"+"+ time +"');</script>");
#region 测试版
//this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('123123!');</script>");
if (Session["token"] != null || Session["openid"] != null || Session["niname"] != null)
{
Response.Write("<script language=javascript>alert('" + Session["openid"] + "+" + Session["token"] + "+" + Session["niname"] + "');</script>");
#region 直接把从腾讯获取的到的信息存到数据中
wxh.Model.oauthinfo mod = new oauthinfo();
wxh.BLL.oauthBLL bll = new oauthBLL();
mod.OpenID = Session["openid"].ToString();
mod.Token = Session["token"].ToString();
mod.NickName = Session["niname"].ToString();
bll.Add(mod);
Response.Redirect("Resite.aspx");
//Session["OAuth2"] = openid;//把OPenid存到session里面
#endregion
#region 无用代码,全注释掉了。
//Response.Write("<script language=javascript>alert('" + token + "+" + openid + "+"+ niname +"+"+ head +"+"+ time +"');</script>");
//Response.Write("<script language=javascript>alert('" + mod.OpenID + "+" + mod.Token + "+" + mod.NickName + "+" + mod.HeadUrl + "+" + mod.ExpireTime + "');</script>");
#region 插入登录日志
//wxh.BLL.Log1BLL blllog = new Log1BLL();
//wxh.Model.Log1Info modlog = new Log1Info();
//modlog.name =openid;//记录登陆的OAuth2;
//modlog.dt = DateTime.Now;
//modlog.eventid = 1;//当前事件
#endregion
#region 插入新闻
wxh.BLL.NewsBLL bllnews = new wxh.BLL.NewsBLL();
wxh.Model.NewsInfo modnews = new wxh.Model.NewsInfo();//账号第一次申请的时候添加该信息
modnews.News_Type = "信息";
modnews.PostDate = DateTime.Now;
modnews.User_name = Session["openid"].ToString();
modnews.china_Newstitle = "视频监控系统";
modnews.china_Newscontent = Session["openid"] + ",欢迎您使用本系统,祝您生活愉快!";
modnews.usa_Newstitle = "Video surveillance system";
modnews.usa_Newscontent = ob.openID + ",You are welcome to use this system, I wish you a happy life!";
modnews.isRead = "false";
#endregion
//Response.Write("<script language=javascript>alert('已经执行到了插入数据之前拉!');</script>");
//return;
//执行数据操作,插入到oauth表
//this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('插入到oauth表出错拉!');</script>");
//添加新闻
//bllnews.Add(modnews);
//this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('插入到news表出错拉!');</script>");
//添加日志记录
//blllog.Add(modlog);
//this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('插入到log表出错拉!');</script>");
//不管有木有绑定,都跳转到Main.aspx页面,和正常用户一样
#endregion
}
#endregion
}
}
//读取授权失败。
else
{
//提示用户重试,或改用其它社区方法登陆。
}
} OAuth 第三方登录 MYsql --------------------编程问答-------------------- 急啊,在线等大神答复。。
补充:.NET技术 , C#