Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XML
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 6-Oct-12 8:19am
Comments
Zoltán Zörgő at 6-Oct-12 14:51pm
   
Store a database in an xml? Where: on client or on the server? And why?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 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:
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"] = "";
}
} 
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 335
1 OriginalGriff 250
2 DamithSL 170
3 Kornfeld Eliyahu Peter 130
4 Peter Leow 95
0 OriginalGriff 7,315
1 DamithSL 5,199
2 Sergey Alexandrovich Kryukov 4,917
3 Maciej Los 4,866
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100