una curiosità, non capisco quanto dura il cookie che viene settato usando l'autenticazione da form (quando faccio il FormsAuthentication.RedirectFromLoginPage(nome,coo kie))
è possibile settare una scadenza che voglio io di questo cookie?
Grazie!
una curiosità, non capisco quanto dura il cookie che viene settato usando l'autenticazione da form (quando faccio il FormsAuthentication.RedirectFromLoginPage(nome,coo kie))
è possibile settare una scadenza che voglio io di questo cookie?
Grazie!
Response.Cookies("NomeCookie").Expires = DateTime.FromString("1/1/2003")
Oppure
Response.Cookies("NomeCookie").Expires = DateTime.Now.AddMonths(1)
Il primo imposta l'eliminazione del cookie al 1 gennaio 2003, il secondo ad un mese dalla sua creazione.
Hey hey, my my Rock and roll can never die!
quello che chiedevo era per il cookie dell'autenticazione...
Quando definisci il nuovo ticket usi la new dove imposti il tempo di timeout.
Così riporta microsoft
Public Sub New( _
ByVal version As Integer, _
ByVal name As String, _
ByVal issueDate As DateTime, _
ByVal expiration As DateTime, _
ByVal isPersistent As Boolean, _
ByVal userData As String, _
ByVal cookiePath As String _
)
version
The version number.
name
User name associated with the ticket.
issueDate
Time at which the cookie was issued.
expiration
Expiration date for the cookie.
isPersistent
True if the cookie is persistent.
userData
User-defined data to be stored in the cookie.
cookiePath
The path for the cookie.
Fammi sapere
Ciao
Kalman
Kalman
Questo è il codice che uso sul form di login al quale l'utente viene indirizzato in quanto non riconosciuto:
Sub btnLogin_Click(objSender As Object, objArgs As EventArgs)
Dim strUserName as string = txtUserName.Text
Dim strPassword as string = txtPassword.Text
Dim blnIsAutenticato as Boolean = False
Dim objConnection as new OleDbConnection
Dim objCommand as new OleDbCommand
Dim objDataReader as OleDbDataReader
Dim strSQL as String
strSQL = "SELECT Password FROM tabUtente WHERE UserName = '" _
& strUserName & "' AND Password = '" & strPassword & "'"
Try
objConnection.ConnectionString = ctlConnectionStrings.OLEDBConnectionString
objConnection.Open
objCommand.CommandText = strSQL
objCommand.Connection = objConnection
objDataReader = objCommand.ExecuteReader()
if objDataReader.Read() Then
if objDataReader("Password") = strPassword then
blnIsAutenticato = True
end if
end if
objDataReader.Close()
objConnection.Close()
Catch objError as Exception
lblMessaggio.Visible = True
lblMessaggio.text = " Errore: " & objError.Message
Exit Sub
End Try
if blnIsAutenticato Then
FormsAuthentication.RedirectFromLoginPage(txtUserN ame.text, chkPersist.Checked)
else
lblMessaggio.Visible = True
lblMessaggio.text = "Utente non riconosciuto!"
end if
End Sub
il problema di settare il cookie è nel redirect (in grassetto).
Non ho capito cosa vuoi dirmi e dove mettere il new....
Quello che faccio io è un po' differente.
Mi creo un ticket di validazione... e di questo ticket conosco il tempo di validità
AutTicket = New FormsAuthenticationTicket(1, strUserId, DateTime.Now, DateTime.Now.AddMinutes(60), False, "")
encTicket = FormsAuthentication.Encrypt(AutTicket)
AutCookie = New HttpCookie(FormsAuthentication.FormsCookieName,enc Ticket)
Response.Cookies.Add(AutCookie)
Ciao
Kalman
Kalman