这个是注册界面
----------------------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.Text;
using System.Security.Cryptography;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtName.Attributes["onkeyup"] = "value=value.replace(/[^\\w+$]/g,'')";
}
}
protected bool isName(string UserName)
{
string strcon = ConfigurationSettings.AppSettings["strCon"];
string sqlstr = "select count(*) from Users where UserName = '" + UserName + "'";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand(sqlstr, conn);
if (Convert.ToInt32(cmd.ExecuteScalar()) > 0)
{
return true;
}
else
{
return false;
}
}
protected void queren_Click(object sender, EventArgs e)
{
if (isName(txtName.Text))
{
labIsName.Text = "用户名已存在!";
labIsName.ForeColor = System.Drawing.Color.Red;
RegisterStartupScript("", "<script>alert('请正确填写信息!')</script>");
}
else
{
string strcon = ConfigurationSettings.AppSettings["strCon"].ToString();
string UserName;
string MdPswdStr = GetMd5(txtPWD.Text.ToString());
UserName = txtName.Text.ToString();
string UserPWD = MdPswdStr;
string UserEmail = UserEmail.Text.ToString();
string UserSex = "";
if (radlistSex.SelectedValue.Trim() == "男")
{
UserSex = "男";
}
else
{
UserSex = "女";
}
string UserQue = UserQue.Text;
string UserAns = UserAns.Text;
if (!isName(txtName.Text))
{
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
string strsql = "insert into Users(UserName,UserSex,UserPWD,UserEmail,UserQue,UserAns) values( '" + UserName + "','" + UserSex + "','" + UserPWD + "','" + UserEmail + "','" + UserQue + "','" + UserAns + "')";
SqlCommand cmd = new SqlCommand(strsql, conn);
if (Convert.ToInt32(cmd.ExecuteNonQuery()) > 0)
{
RegisterStartupScript("true", "<script>alert('恭喜您,注册成功……')</script>");
txtName.Text = txtPWD.Text = txtEmail.Text = txtPWD2.Text = "";
labIsName.Text = "";
}
else
{
RegisterStartupScript("true", "<script>alert('请正确填写信息!')</script>");
}
conn.Close();
}
else
{
RegisterStartupScript("true", "<script>alert('用户名不能为空!')</script>");
}
} }
public static string GetMd5(string str)
{
string cl = DateTime.Now.Month + str + DateTime.Now.Day;
string UawePWD = "";
MD5 md5 = MD5.Create();
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
s.Reverse();
for (int i = 3; i < s.Length - 1; i++)
{
UawePWD = UawePWD + (s[i] < 198 ? s[i] + 28 : s[i]).ToString("X");
}
return UawePWD;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txtName.Text == "")
{
labIsName.Text = "用户名不能为空";
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
if (isName(txtName.Text))
{
labIsName.Text = "用户名已存在!";
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
labIsName.Text = "可以注册!";
labIsName.ForeColor = System.Drawing.Color.Blue;
}
}
}
}--------------------------------
这个是登陆界面---------------------------------
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.Text;
using System.Security.Cryptography;
public partial class Default2 : System.Web.UI.Page
{
string UserName;
string UserPWD;
protected void Page_Load(object sender, EventArgs e)
{ }
protected void denglu_Click(object sender, EventArgs e)
{
if (UserName.Text.Trim() != "" & UserPWD.Text.Trim() != "")
{
string MdPswdStr = GetMd5(UserPWD.Text.ToString());
UserName = UserName.Text.ToString();
UserPWD = MdPswdStr;
if (Request.Cookies["user"] != null & Request.Cookies["pwd"] != null)
{
HttpCookie cuser = Request.Cookies["user"];
cuser.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cuser);
HttpCookie cpwd = Request.Cookies["pwd"];
cpwd.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cpwd);
}
string strcon = ConfigurationSettings.AppSettings["strCon"];
SqlConnection myconn = new SqlConnection(strcon);
string strsql = "select * from Users where UserName=@name and PassWord=@pass";
SqlCommand comm = new SqlCommand(strsql, myconn);
myconn.Open();
comm.Parameters.Add(new SqlParameter("name", SqlDbType.NVarChar, 50));
comm.Parameters["name"].Value = UserName;
comm.Parameters.Add(new SqlParameter("pass", SqlDbType.NVarChar, 50));
comm.Parameters["pass"].Value = UserPWD;
if (Convert.ToInt32(comm.ExecuteScalar()) > 0)
{
switch (ddlSave.SelectedValue)
{
case "1":
CacheAddDate(7);
break;
case "2":
CacheAddDate(14);
break;
}
Response.Write("<script>alert('登录成功!');location='UserRegister.aspx'</script>");
UserName.Text = UserPWD.Text = "";
}
else
{
Response.Write("<script>alert('用户名或密码错误!');location='UserRegister.aspx'</script>");
}
myconn.Close();
}
else
{
if (Request.Cookies["user"] != null & Request.Cookies["pwd"] != null)
{ Response.Write("<script>alert('登录成功!');location='Default.aspx'</script>");
}
Response.Write("<script>alert('用户名或密码错误!');location='Default.aspx'</script>");
}
} protected void CacheAddDate(int adddate)
{
Response.Cookies["user"].Value = UserName;
Response.Cookies["user"].Expires = DateTime.Now.AddDays(adddate);
Response.Cookies["pwd"].Value = UserPWD;
Response.Cookies["pwd"].Expires = DateTime.Now.AddDays(adddate);
} public static string GetMd5(string str)
{
string cl = DateTime.Now.Month + str + DateTime.Now.Day;
string UserPWD = "";
MD5 md5 = MD5.Create();
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
s.Reverse();
for (int i = 3; i < s.Length - 1; i++)
{
UserPWD = UserPWD + (s[i] < 198 ? s[i] + 28 : s[i]).ToString("X");
}
return UserPWD;
}
}错误是这些的:错误:“string”不包含“Text”的定义,并且找不到可接受类型为“string”的第一个参数的扩展方法“Text”(是否缺少 using 指令或程序集引用?) F:\WebSite38\Default2.aspx.cs 69 26 F:\WebSite38\
----------------------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.Text;
using System.Security.Cryptography;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtName.Attributes["onkeyup"] = "value=value.replace(/[^\\w+$]/g,'')";
}
}
protected bool isName(string UserName)
{
string strcon = ConfigurationSettings.AppSettings["strCon"];
string sqlstr = "select count(*) from Users where UserName = '" + UserName + "'";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand(sqlstr, conn);
if (Convert.ToInt32(cmd.ExecuteScalar()) > 0)
{
return true;
}
else
{
return false;
}
}
protected void queren_Click(object sender, EventArgs e)
{
if (isName(txtName.Text))
{
labIsName.Text = "用户名已存在!";
labIsName.ForeColor = System.Drawing.Color.Red;
RegisterStartupScript("", "<script>alert('请正确填写信息!')</script>");
}
else
{
string strcon = ConfigurationSettings.AppSettings["strCon"].ToString();
string UserName;
string MdPswdStr = GetMd5(txtPWD.Text.ToString());
UserName = txtName.Text.ToString();
string UserPWD = MdPswdStr;
string UserEmail = UserEmail.Text.ToString();
string UserSex = "";
if (radlistSex.SelectedValue.Trim() == "男")
{
UserSex = "男";
}
else
{
UserSex = "女";
}
string UserQue = UserQue.Text;
string UserAns = UserAns.Text;
if (!isName(txtName.Text))
{
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
string strsql = "insert into Users(UserName,UserSex,UserPWD,UserEmail,UserQue,UserAns) values( '" + UserName + "','" + UserSex + "','" + UserPWD + "','" + UserEmail + "','" + UserQue + "','" + UserAns + "')";
SqlCommand cmd = new SqlCommand(strsql, conn);
if (Convert.ToInt32(cmd.ExecuteNonQuery()) > 0)
{
RegisterStartupScript("true", "<script>alert('恭喜您,注册成功……')</script>");
txtName.Text = txtPWD.Text = txtEmail.Text = txtPWD2.Text = "";
labIsName.Text = "";
}
else
{
RegisterStartupScript("true", "<script>alert('请正确填写信息!')</script>");
}
conn.Close();
}
else
{
RegisterStartupScript("true", "<script>alert('用户名不能为空!')</script>");
}
} }
public static string GetMd5(string str)
{
string cl = DateTime.Now.Month + str + DateTime.Now.Day;
string UawePWD = "";
MD5 md5 = MD5.Create();
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
s.Reverse();
for (int i = 3; i < s.Length - 1; i++)
{
UawePWD = UawePWD + (s[i] < 198 ? s[i] + 28 : s[i]).ToString("X");
}
return UawePWD;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txtName.Text == "")
{
labIsName.Text = "用户名不能为空";
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
if (isName(txtName.Text))
{
labIsName.Text = "用户名已存在!";
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
labIsName.Text = "可以注册!";
labIsName.ForeColor = System.Drawing.Color.Blue;
}
}
}
}--------------------------------
这个是登陆界面---------------------------------
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.Text;
using System.Security.Cryptography;
public partial class Default2 : System.Web.UI.Page
{
string UserName;
string UserPWD;
protected void Page_Load(object sender, EventArgs e)
{ }
protected void denglu_Click(object sender, EventArgs e)
{
if (UserName.Text.Trim() != "" & UserPWD.Text.Trim() != "")
{
string MdPswdStr = GetMd5(UserPWD.Text.ToString());
UserName = UserName.Text.ToString();
UserPWD = MdPswdStr;
if (Request.Cookies["user"] != null & Request.Cookies["pwd"] != null)
{
HttpCookie cuser = Request.Cookies["user"];
cuser.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cuser);
HttpCookie cpwd = Request.Cookies["pwd"];
cpwd.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cpwd);
}
string strcon = ConfigurationSettings.AppSettings["strCon"];
SqlConnection myconn = new SqlConnection(strcon);
string strsql = "select * from Users where UserName=@name and PassWord=@pass";
SqlCommand comm = new SqlCommand(strsql, myconn);
myconn.Open();
comm.Parameters.Add(new SqlParameter("name", SqlDbType.NVarChar, 50));
comm.Parameters["name"].Value = UserName;
comm.Parameters.Add(new SqlParameter("pass", SqlDbType.NVarChar, 50));
comm.Parameters["pass"].Value = UserPWD;
if (Convert.ToInt32(comm.ExecuteScalar()) > 0)
{
switch (ddlSave.SelectedValue)
{
case "1":
CacheAddDate(7);
break;
case "2":
CacheAddDate(14);
break;
}
Response.Write("<script>alert('登录成功!');location='UserRegister.aspx'</script>");
UserName.Text = UserPWD.Text = "";
}
else
{
Response.Write("<script>alert('用户名或密码错误!');location='UserRegister.aspx'</script>");
}
myconn.Close();
}
else
{
if (Request.Cookies["user"] != null & Request.Cookies["pwd"] != null)
{ Response.Write("<script>alert('登录成功!');location='Default.aspx'</script>");
}
Response.Write("<script>alert('用户名或密码错误!');location='Default.aspx'</script>");
}
} protected void CacheAddDate(int adddate)
{
Response.Cookies["user"].Value = UserName;
Response.Cookies["user"].Expires = DateTime.Now.AddDays(adddate);
Response.Cookies["pwd"].Value = UserPWD;
Response.Cookies["pwd"].Expires = DateTime.Now.AddDays(adddate);
} public static string GetMd5(string str)
{
string cl = DateTime.Now.Month + str + DateTime.Now.Day;
string UserPWD = "";
MD5 md5 = MD5.Create();
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
s.Reverse();
for (int i = 3; i < s.Length - 1; i++)
{
UserPWD = UserPWD + (s[i] < 198 ? s[i] + 28 : s[i]).ToString("X");
}
return UserPWD;
}
}错误是这些的:错误:“string”不包含“Text”的定义,并且找不到可接受类型为“string”的第一个参数的扩展方法“Text”(是否缺少 using 指令或程序集引用?) F:\WebSite38\Default2.aspx.cs 69 26 F:\WebSite38\
string UserAns = UserAns.Text;这个地方你定义的变量和控件重名了。
例如 一个textbox的,的name属性,命名为 txbUserName,你的变量可以命名为 strUserName
=>
string UserEmail = txtEmail.Text.ToString();应该是你打错了的缘故