pettrer:I don't want to be a nag, but I for one does not find this easy. But as there are so many links to that MSDN article, how come there's no tutorial or example code out there?
I've tried to do this for a weeek now and honestly, my (poor) employer would rather have had me done something else... ;-)
Please anyone... tutorial perhaps? :-)
Pettrer
Well I am happy to show you what I have achieved thus far.
This is the VB code for my Login.aspx and so far the Login page does communicate and authenticate with the database.
I am now currently working on expanding on this.
1 <script language="VB" runat="server">
2 Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean
3
4 End Function
5
6 'Sub doLogin(ByVal Source As Object, ByVal E As EventArgs)
7 ' If ValidateUser(txtUID.Text, txtPWD.Text) = True Then
8 ' FormsAuthentication.RedirectFromLoginPage(txtUID.Text, False)
9 ' Else
10 ' lblError.Visible = "True"
11 ' lblError.text = "We're sorry, but the information you provided " & _
12 ' "does not match our database. Please try again."
13 ' ValidateUser.Text = ""
14 ' End If
15 'End Sub
16
17 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
18 If Page.IsPostBack Then
19
20
21 Dim sText As String
22 Dim blnValidUser
23 Dim sUser, sPwd As String
24
25 Dim sFirst, sName, sLast As String
26 Dim strConn As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\A2Z.mdf;Integrated Security=True;User Instance=True"
27 Dim MySQL As String = "Select [Name], [Login], " & _
28 "[Password] from Login " & _
29 "Where Login=@uid AND Password=@Pwd"
30 Dim MyConn As New Data.SqlClient.SqlConnection(strConn)
31 Dim objDR As Data.SqlClient.SqlDataReader
32 Dim Cmd As New Data.SqlClient.SqlCommand(MySQL, MyConn)
33 Cmd.Parameters.Add(New Data.SqlClient.SqlParameter("@Uid", txtUID.Text))
34 Cmd.Parameters.Add(New Data.SqlClient.SqlParameter("@Pwd", txtPWD.Text))
35 MyConn.Open()
36
37
38
39 Try
40 objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
41 While objDR.Read()
42
43 sUser = objDR("login")
44 sPwd = objDR("Password")
45 sName = objDR("Name")
46 Response.Write(sName)
47 End While
48
49 If sFirst = "" And sLast = "" Then
50 blnValidUser = "False"
51 Else
52 blnValidUser = "True"
53 Session("Name") = sName
54 End If
55 Catch ex As Exception
56 lblError.Visible = "true"
57 lblError.Text = "Sorry Errors have occurred"
58 End Try
59 End If
60 End Sub
61 </script>
Here is the change I made to the Web.config
<authentication mode="Forms">
<forms name="myWebPageCookie"
loginUrl="login.aspx"
timeout="30">
</forms>
</authentication>
<authorization>
<allow users="?" />
<deny users="*" />
</authorization>
I hope this helps you in any way, I will give you my full solution once I have done it.