Oggetto sessione ASP
Un oggetto Session memorizza informazioni o modifica le impostazioni per una sessione utente.
Altri esempi
Imposta o restituisce un numero intero che specifica una posizione o una regione. Contenuti come data, ora e valuta verranno visualizzati in base a quella località o regione.
Restituisce un ID univoco per ogni utente. L'ID è generato dal server.
Imposta e restituisce il timeout (in minuti) di una sessione.
Oggetto Sessione
Quando lavori con un'applicazione sul tuo computer, la apri, apporti alcune modifiche e poi la chiudi. Questo è molto simile a una Sessione. Il computer sa chi sei. Sa quando apri l'applicazione e quando la chiudi. Tuttavia, su Internet c'è un problema: il web server non sa chi sei e cosa fai, perché l'indirizzo HTTP non mantiene lo stato.
ASP risolve questo problema creando un cookie univoco per ogni utente. Il cookie viene inviato al computer dell'utente e contiene informazioni che identificano l'utente. Questa interfaccia è chiamata oggetto Session.
L'oggetto Session memorizza informazioni o modifica le impostazioni per una sessione utente.
Le variabili archiviate in un oggetto Session contengono informazioni su un singolo utente e sono disponibili per tutte le pagine di un'applicazione. Le informazioni comuni memorizzate nelle variabili di sessione sono nome, ID e preferenze. Il server crea un nuovo oggetto Session per ogni nuovo utente e distrugge l'oggetto Session alla scadenza della sessione.
Le raccolte, le proprietà, i metodi e gli eventi dell'oggetto Session sono descritti di seguito:
Collezioni
Collection | Description |
---|---|
Contents | Contains all the items appended to the session through a script command |
StaticObjects | Contains all the objects appended to the session with the HTML <object> tag |
Proprietà
Property | Description |
---|---|
CodePage | Specifies the character set that will be used when displaying dynamic content |
LCID | Sets or returns an integer that specifies a location or region. Contents like date, time, and currency will be displayed according to that location or region |
SessionID | Returns a unique id for each user. The unique id is generated by the server |
Timeout | Sets or returns the timeout period (in minutes) for the Session object in this application |
Metodi
Method | Description |
---|---|
Abandon | Destroys a user session |
Contents.Remove | Deletes an item from the Contents collection |
Contents.RemoveAll() | Deletes all items from the Contents collection |
Eventi
Event | Description |
---|---|
Session_OnEnd | Occurs when a session ends |
Session_OnStart | Occurs when a session starts |