Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am a new user of ASp.NET. I was just surfing and was curious to know how i can store information like a database in XML and later use it in Login purpose type example.
Posted
Comments
Zoltán Zörgő 6-Oct-12 14:51pm    
Store a database in an xml? Where: on client or on the server? And why?

1 solution

What I understand from your question is you want to login into a ASP.NET website making use of a XML file. XML file contains login username-password information and you want to use it for authentication. If so, look at the following:
Video: How To Pull Data From An XML File Using ASP.NET[^]
Login using XML file in ASP.NET using C#[^]
Form Authentication in ASP.NET using XML[^]

Sample:
LoginData.xml
XML
<?xml version="1.0" encoding="utf-8" ?>
<employee>
<User>
<username>bikrantsingh</username>
<password>bikrant123</password>
</User>
<User>
<username>anuragsingh</username>
<password>anurag</password>
</User>
<User>
<username>saurabh</username>
<password>saurabh123</password>
</User>
</employee>


Code behind:
C#
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("~/App_Data/Loginxml.xml"));
XmlNodeList xmlnodelist = xmxdoc.GetElementsByTagName("User");
foreach (XmlNode xn in xmlnodelist)
{
XmlNodeList xmlnl = xn.ChildNodes;
foreach (XmlNode xmln in xmlnl)
{
if (xmln.Name == "username")
{
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("Default2.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
} 
}
 
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