Need help in reading the data from credentials xml file
I want to read the username and password from credentials xml file. For successful login it should go to destination page or for invalid login it should display the invalid username or password. Suppose i have many no of username and password in credential.xml file, user can dynamically enter any of the combination username and password. Pls somebody help me how can do this...i have written the code but throwing error "Object reference not set to an instance of an object." Here is my Credentials.xml
<logininfo>
<crendential>
<username>Rahul1</username>
<password>124356</password>
</crendential>
<crendential>
<username>Rahul2</username>
<password>654321</password>
</crendential>
<crendential>
<username>Rahul3</username>
<password>852741</password>
</crendential>
</logininfo>
code behind aspx.cs page:
protected void BtnLogin_Click(object sender, EventArgs e)
{
XmlDocument doc开发者_Python百科 = new XmlDocument();
doc.Load(Server.MapPath("Credentials.xml"));
XmlNode root=doc.DocumentElement;
string username = root.SelectSingleNode("username").ChildNodes[0].Value;
string password = root.SelectSingleNode("password").ChildNodes[0].Value;
string user = TxtUserName.Text.Trim();
string pass = TxtPassword.Text.Trim();
if ((user == username) && (pass == password))
{
Session["User"] = username;
Response.Redirect("destinationpage.aspx");
}
else
{
lblError.Text="Invalid userid or password";
}
}
string username = root.SelectNodes("//username")[0].InnerText; // Rahul1
username = root.SelectNodes("//username")[1].InnerText; // Rahul2
username = root.SelectNodes("//username")[2].InnerText; // Rahul3
精彩评论