Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We are using Login form using xml file already i insert a data into xml.
my code has some errors......plz help me



while i am executing this it check all elements Email,Gender,Location,DateOfBirth including Name and password
directly o/p shows like this: "Plz check UR Username and Password"
My xml file

XML
<employees>
  <Name>vamsi</Name>
  <Password>vamsi123</Password>
  <Email>vamsi@123</Email>
  <Gender>Male</Gender>
  <Location>Hyderbad</Location>
  <DateOfBirth>22/05/1988</DateOfBirth>
</employees>




C#
try
        {
            XmlDocument myxmldocument = new XmlDocument();
            //XmlTextReader reader = new XmlTextReader(Server.MapPath("Register.xml"));
            myxmldocument.Load("Register.xml");
            XmlNodeReader reader=new XmlNodeReader(myxmldocument);
            
             myxmldocument.Load(Server.MapPath("Register.xml"));
            while (reader.Read())
            {

                 reader.MoveToElement();
                if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Name"))
                {
                    string sname;
                    sname = reader.ReadString();
                    if (sname != TextBox1.Text)
                    {
                        reader.Skip();
                    }
                

                 else if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Password"))
                    {
                        string spass;
                        spass = reader.ReadString();
                        if (spass == TextBox2.Text)
                        {
                            Response.Redirect("Welcome.aspx");
                        }

                    }
}
                }

            
            lblmsg.Text = "Plz check UR Username and Password";
        }
        catch (Exception ex)
        {
            lblmsg.Text = ex.Message;
        }
Posted
Updated 4-Mar-12 22:03pm
v6
Comments
Sudip Saha 5-Mar-12 0:43am    
What is error you are having ...please mention in question
Uday P.Singh 5-Mar-12 1:04am    
mention the error message! so that we can help you better.

hiiii guys i get solution for this if i tale login control it is easy for
me if we give any modifications for above code plz mail me tirumalarao.kodumuri@gmail.com


the solution for above is

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string username;
string pwd;
string CurrentUser = "";
string CurrentPwd = "";
bool LoginStatus = false;
username = Login1.UserName;
pwd = Login1.Password;
XmlDocument xmxdoc = new XmlDocument();
xmxdoc.Load(Server.MapPath("Register.xml"));
XmlNodeList xmlnodelist = xmxdoc.GetElementsByTagName("employees");
foreach (XmlNode xn in xmlnodelist)
{
XmlNodeList xmlnl = xn.ChildNodes;
foreach (XmlNode xmln in xmlnl)
{
if (xmln.Name == "Name")
{
if (xmln.InnerText == username)
{
CurrentUser = username;
}
}
if (xmln.Name == "Password")
{
if (xmln.InnerText == pwd)
{
CurrentPwd = pwd;
}
}
}
if ((CurrentUser != "") & (CurrentPwd != ""))
{
LoginStatus = true;
}
}
if (LoginStatus == true)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("welcome.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}
 
Share this answer
 
plz check the if loops below is there any error plz tell me
C#
try
        {
            XmlDocument myxmldocument = new XmlDocument();
            XmlTextReader reader = new XmlTextReader(Server.MapPath("Register.xml"));
            
             myxmldocument.Load(Server.MapPath("Register.xml"));
             while (reader.Read())
             {

                 
                 if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Name"))
                 {
                     string sname;
                     sname = reader.ReadString();
                     if (sname != TextBox1.Text)
                     {
                         lblmsg.Text = "Plz check UR Username";
                         reader.Skip();
                     }
                     if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Password"))
                     {
                         string spass;
                         spass = reader.ReadString();
                         if (spass == TextBox2.Text)
                         {
                             Response.Redirect("Welcome.aspx");
                         }
                         else
                         {
                             reader.Skip();
                         }
     
                     }
                 }
             }

            
            lblmsg.Text = "Plz check UR Username and Password";
 
Share this answer
 
v2
Comments
Anuja Pawar Indore 5-Mar-12 2:26am    
Added code block
Hi,
Your solution here: Loading a DataSet from XML (ADO.NET)[^] Please check.
 
Share this answer
 
ok
but our aim is with out using xml(ADO.net).....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900