Here is a very simple example on how to do this.
Database:
Type: Microsoft Excel
File Name: users.xls
Sheet Name: users
users.gif
Login WebForm Code:
Login Code Behind:
vb.net Code:
Imports System.Data.OleDb
Partial Public Class _Default
Inherits System.Web.UI.Page
Private Shared lsConnectionString As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim lsPath As String = Request.PhysicalApplicationPath & "users.xls"
lsConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & lsPath & ";Extended Properties=Excel 8.0;"
End Sub
Protected Sub Login1_Authenticate(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim lsQuery As String = "SELECT * FROM [users$]"
Dim loConnection = New OleDbConnection(lsConnectionString)
Dim loCommand As New OleDbCommand(lsQuery, loConnection)
Dim lsUsername, lsPassword, lsUserType As String
Dim loReader As IDataReader
loConnection.Open()
loReader = loCommand.ExecuteReader()
While (loReader.Read())
lsUsername = CStr((loReader("username")))
lsPassword = CStr((loReader("password")))
lsUserType = CStr((loReader("usertype")))
If Login1.UserName = lsUsername AndAlso Login1.Password = lsPassword Then
Response.Write("Login Successful!")
e.Authenticated = True
Session("Authenticated") = True
Session("username") = lsUsername
Session("password") = lsPassword
Session("usertype") = lsUserType
Response.Redirect("Default.aspx")
Exit While
End If
End While
End Sub
End Class
Success Web Form:
Success Code Behind:
vb.net Code:
Public Partial Class _Default1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("Authenticated") = True Then
Response.Write("Welcome " & Session("username") & "!<br />")
Response.Write("User Type: " & Session("usertype"))
Else
Response.Redirect("Login.aspx")
End If
End Sub
End Class
Sample Project is attached bellow. I hope this helps!
Pete