Asp.Net 判断储存在xml文件中的用户名合法性(登陆操作)

XML文件请见 ASP.Net中实现XMl的标识列(ID列)或自增长列
登陆按钮事件:
None.gif   private   void  Btn_login_Click( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
string username = this.txt_name.Text.Trim();
InBlock.gif            
string userpass = this.txt_pass.Text.Trim();
InBlock.gif            
string filename = Server.MapPath(".//XMl/User.xml");
InBlock.gif            
string str = OperateXmlByDataSet.UserLogin(filename,"username",username,"userpass",userpass);  
InBlock.gif            Session[
"username"]=str;
InBlock.gif            
if(str!="sorry")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Lab_flag.Text=str+"登陆成功!";
InBlock.gif             dot.gifdot.gif
//登陆成功后的操作     }
InBlock.gif
            else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Lab_flag.Text="请重新登陆";
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }
文中用到OperateXmlByDataSet的UserLogin方法,代码如下:
ContractedBlock.gif ExpandedBlockStart.gif   用户登陆 #region 用户登陆
InBlock.gif        
public static string UserLogin(string strXmlPath,string column1 ,string values1,string column2,string values2)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{                            
InBlock.gif                
string strXsdPath = strXmlPath.Substring(0,strXmlPath.IndexOf(".")) + ".xsd";
InBlock.gif                DataSet ds 
= new DataSet();
InBlock.gif                ds.ReadXml(GetXmlFullPath(strXmlPath));
InBlock.gif                
string str="sorry";
InBlock.gif                
//先判断行数
InBlock.gif
                if(ds.Tables[0].Rows.Count > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{                    
InBlock.gif                    
for(int i=0; i< ds.Tables[0].Rows.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
//如果当前记录为符合Where条件的记录
InBlock.gif
                        if(ds.Tables[0].Rows[i][column1].ToString().Trim().Equals(values1))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
//循环给找到行的各列赋新值
InBlock.gif
                            if(ds.Tables[0].Rows[i][column2].ToString().Trim().Equals(values2))
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                str 
= ds.Tables[0].Rows[i][column1].ToString();
InBlock.gif                                
return str;
ExpandedSubBlockEnd.gif                            }

InBlock.gif                            
return str ;
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }
                    
InBlock.gif                    
ExpandedSubBlockEnd.gif                }
                    
InBlock.gif                
return str;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return e.Message;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
#endregion

转载于:https://www.cnblogs.com/tenghoo/archive/2006/10/11/525974.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值