Ecco il codice della pagina login.aspx:
codice:
<%@ Page Language="VB" debug="true"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>Loginnati!</title>
<script runat="server" language="VB">
Sub Page_Load()
Dim errore As Integer
errore = Request.Params("error")
If errore = 1 Then
Response.Write("<p class='error'>errore durante il login</p>")
End If
If Session.Item("login") = 1 Then
response.Redirect("categorie.aspx") 'se ho già effettuato il login entro direttamente nella pagina protetta
End If
End Sub
Sub Login(sender As Object, e As System.EventArgs)
Dim Con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
+ "Data Source=C:\Inetpub\wwwroot\provedw\sito\db\prova.mdb")
Dim sqlString = "SELECT * FROM login WHERE pwd ='" & txtPass.Text & "' AND username='" & txtId.Text & "'"
Dim myCommand As New OleDbCommand(sqlString, Con)
Dim objReader As oleDbDataReader
Con.Open()
objReader = myCommand.ExecuteReader()
If Not objReader.Read() Then 'vedo se ci sono risultati x quel nomeutente e password
Response.Redirect("login.aspx?error=1") 'se no rimando alla stessa pagina segnalando l'errore
Else
Session.Item("login") = 1 'trovato un risultato imposto a 1 la variabile di sessione login
Response.Redirect("categorie.aspx") 'e redirecto l'utente sulla pagina protetta
End If
objReader.Close()
Con.Close()
End Sub
</script>
</head>
<body>
<form method="post" name="login" runat="server">
ID : <asp:TextBox id="txtId" rows="1" width="120" runat="server" />
password : <asp:TextBox id="txtPass" textmode="password" rows="1" width="120" runat="server" />
<asp:Button id="btnSubmit" runat="server" text="entra" onClick="Login" />
</form>
</body>
</html>
Mentre il codice del file global.asax è:
codice:
<%@ Application language="VB" %>
<script runat="server">
Sub Application_Start(Sender As Object, E As EventArgs)
End Sub
Sub Application_End(Sender As Object, E As EventArgs)
End Sub
Sub Application_Error(Sender As Object, E As EventArgs)
End Sub
Sub Session_Start(Sender As Object, E As EventArgs)
session("login") = 0
End Sub
Sub Session_End(Sender As Object, E As EventArgs)
End Sub
</script>
Ciao e grazie. :tongue: