Library code snippets
Forms Authentication Against An XML File
This code shows how to validate against an XML file for Forms Authentication security in ASP.Net. Please read one of the earlier articles on Forms Authentication for an introduction and to see the required settings in the web.config file. The code below is just a modification of the login.aspx page.
<%@Page Language="VB" Trace="false"%>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Xml" %>
<script language="VB" runat=server>
Sub ValidateLogin(Src as Object, E as EventArgs)
Dim sXmlPath As String = "C:\Inetpub\wwwroot\users.xml"
Dim oXmlDoc As New XmlDocument()
Try
oXmlDoc.Load(sXmlPath)
Catch oError As Exception
StatusMessage.innerHTML = "There was an error:<BR>" & oError.Message & "<BR>" _
& oError.Source & "."
Exit Sub
End Try
Dim oXmlUser As XmlNodeList
oXmlUser = oXmlDoc.GetElementsByTagname(txtUser.Value)
If Not (oXmlUser Is Nothing) Then
If txtPwd.Value = oXmlUser(0).FirstChild().Value Then
FormsAuthentication.RedirectFromLoginPage(txtUser.Value, false)
Else
StatusMessage.InnerHtml = "Invalid login"
End If
End If
End Sub
</script>
<html>
<head>
<title>Forms Authentication Against An XML File</title>
</head>
<body>
<form method="post" runat="server">
Username: <INPUT type="text" name="txtUser" id="txtUser"
runat="server"/><BR>
Password: <INPUT type="password" name="txtPwd" id="txtPwd"
runat="server"/><BR>
<INPUT type="submit" OnServerClick="ValidateLogin" runat="server"/>
</form>
<SPAN id="StatusMessage" runat="server"/>
</body>
</html>
Related articles
Related discussion
-
Problem in uploading the image using fck editor in asp.net 2.0
by elizas (13 replies)
-
Tree structures in ASP.NET and SQL Server
by nesreen (29 replies)
-
how to create an xml template
by neelanshu (0 replies)
-
Help required to know about sync of RFID read tag thru Handheld-sample code in .net
by usha@myrf (0 replies)
-
How to query multiple xml files?
by lamin (0 replies)
Related podcasts
-
The One With The Maracas ...
Its the last day of the MVP Summit, the boys dive deep into XML and dynamic language sessions all NDA unfortunately so don't expect them to say anything ... But an interview with Russ Nemhauser uncovers his love for the Mac and concern with some project management methodologies. Brad Abrams gets ...
Events coming up
-
Mar
15
DevWeek 2010
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.
This thread is for discussions of Forms Authentication Against An XML File.