English 中文(简体)
需要帮助读取凭据XML文件中的数据。
原标题: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>

载于px.cs页的代码:

protected void BtnLogin_Click(object sender, EventArgs e)
{
    XmlDocument doc = 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




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Remotely authenticating client Windows user on demand

Suppose I am writing a server for a particular network protocol. If I know that the client is running on a Windows machine, is it possible for my server to authenticate the Windows user that owns the ...

Role/Permission based forms authorizing/authentication?

While looking into forms authorizing/authentication, I found that it is possible to do role based authorizing by adding an array of roles to a FormsAuthenticationTicket. That way I can write User....

热门标签