Collection Contents ASP
La collection Contents contient tous les éléments ajoutés à l'application/session via des commandes de script.
Conseil :Pour supprimer un élément de la collection Contents, utilisez les méthodes Remove et RemoveAll.
Syntaxe
Application.Contents(Key) Session.Contents(Key)
Paramètres | Description |
---|---|
clé | Obligatoire. Le nom de l'élément à récupérer. |
Instance de l'objet Application
Exemple 1
Veuillez noter que name et objtest seront ajoutés à la collection Contents :
<% Application("name")="W3School" Set Application("objtest")=Server.CreateObject("ADODB.Connection") %>
Exemple 2
Parcourir la collection Contents :
<% for each x in Application.Contents Response.Write(x & "=" & Application.Contents(x) & "<br />") next %>
Ou :
<% For i=1 to Application.Contents.Count Response.Write(i & "=" & Application.Contents(i) & "<br />") Next %>
Exemple 3
<% Application("date")="2001/05/05" Application("author")="W3School" for each x in Application.Contents Response.Write(x & "=" & Application.Contents(x) & "<br />") next %>
Sortie :
date=2001/05/05 auteur=W3School
Instance de l'objet Session
Exemple 1
Veuillez noter que name et objtest seront ajoutés à la collection Contents :
<% Session("name")="Hege" Set Session("objtest")=Server.CreateObject("ADODB.Connection") %>
Exemple 2
Parcourir la collection Contents :
<% for each x in Session.Contents Response.Write(x & "=" & Session.Contents(x) & "<br />") next %>
Ou :
<% For i=1 to Session.Contents.Count Response.Write(i & "=" & Session.Contents(i) & "<br />") Next %>
Exemple 3
<% Session("name")="Hege" Session("date")="2001/05/05" for each x in Session.Contents Response.Write(x & "=" & Session.Contents(x) & "<br />") next %>
Sortie :
name=Hege date=2001/05/05