Asp.Net 判断储存在xml文件中的用户名合法性(登陆操作)
XML文件请见ASP.Net中实现XMl的标识列(ID列)或自增长列
登陆按钮事件:
登陆按钮事件:
private void Btn_login_Click(object sender, System.EventArgs e)
{
string username = this.txt_name.Text.Trim();
string userpass = this.txt_pass.Text.Trim();
string filename = Server.MapPath(".//XMl/User.xml");
string str = OperateXmlByDataSet.UserLogin(filename,"username",username,"userpass",userpass);
Session["username"]=str;
if(str!="sorry")
{
this.Lab_flag.Text=str+"登陆成功!";
//登陆成功后的操作 }
else
{
this.Lab_flag.Text="请重新登陆";
}
}
文中用到OperateXmlByDataSet的UserLogin方法,代码如下:{
string username = this.txt_name.Text.Trim();
string userpass = this.txt_pass.Text.Trim();
string filename = Server.MapPath(".//XMl/User.xml");
string str = OperateXmlByDataSet.UserLogin(filename,"username",username,"userpass",userpass);
Session["username"]=str;
if(str!="sorry")
{
this.Lab_flag.Text=str+"登陆成功!";
//登陆成功后的操作 }
else
{
this.Lab_flag.Text="请重新登陆";
}
}
用户登陆
作者:青羽