Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=120200040

Contents.Remove / Contents.RemoveAll

Application Object

One of the key functions of Application Object is the application data control on the server.

Application.Contents.Remove Method

Application.Contents.Remove Method removes or deletes an item from the Contents collection of Application object..

Syntax:

Contents.Remove(
    id
)

 Or in an ASP file. Imply

<% Application.Contents.Remove(id) %>

Parameters:

id

The parameter "id" , a string or an integer,  is used to specify the name of the item to be removed. If id is a string, the specified name of the item in the contents collection will be removed. If id is an integer, the corresponding indexed item in the contents collection will be removed.  

Return Values:

void

This method has no return values.

Remarks:

The id can be either a string of an integer. If id is a string, the specified name of the item in the contents collection will be removed. If id is an integer, the corresponding indexed item in the contents collection will be removed.  However, the index of the collection will be updated after the removal of an item from the collection. Therefore, better to identify an item by its name.

The ASP collection support only the Count property and the Item, Remove, and RemoveAll methods. The Add method is not support and the item is added by declaration.

Examples:

  • Use Application.Contents.Remove to remove the specified item

    ASP script command:

    <%
    Application("App1") = "App1value"
    Application.Contents("App2") = "App2value"
    Application.Contents.Item("App3") = "App3value"
    Response.write "Elements in Application.Contents Collection :<br>"
    For Each element in Application.Contents
    Response.write element & " = " & Application(element) & "<br>"
    Next
    Response.write "<br>"
    Response.write "Elements in Application.Contents Collection :<br>"
    Application.Contents.Remove("App2")
    For Each element in Application.Contents
    Response.write element & " = " & Application(element) & "<br>"
    Next
    %>

    HTTP response output:

    Elements in Application.Contents Collection :<br>
    App1 = App1value<br>
    App2 = App2value<br>
    App3 = App3value<br>
    <br>
     Elements in Application.Contents Collection :<br>
    App1 = App1value<br>
    App3 = App3value<br>

    HTML web page ouput:

    Elements in Application.Contents Collection :
    App1 = App1value
    App2 = App2value
    App3 = App3value

    Elements in Application.Contents Collection :
    App1 = App1value
    App3 = App3value

  • Use Application.Contents.Remove to remove the second item

    ASP script command:

    <%
    Application("App1") = "App1value"
    Application.Contents("App2") = "App2value"
    Application.Contents.Item("App3") = "App3value"
    Response.write "Elements in Application.Contents Collection :<br>"
    For Each element in Application.Contents
    Response.write element & " = " & Application(element) & "<br>"
    Next
    Response.write "<br>"
    Response.write "Elements in Application.Contents Collection :<br>"
    Application.Contents.Remove(2)
    For itemno = 1 to Application.Contents.Count 
    Response.Write CStr(itemno) & " = " & _
    Application.Contents(itemno) & "<br>"
    Next
    %>

    HTTP response output:

    Elements in Application.Contents Collection :<br>
    App1 = App1value<br>
    App2 = App2value<br>
    App3 = App3value<br>
    <br>
    Elements in Application.Contents Collection :<br>
    1 = App1value<br>
    2 = App3value<br>

    HTML web page ouput:

    Elements in Application.Contents Collection :
    App1 = App1value
    App2 = App2value
    App3 = App3value

    Elements in Application.Contents Collection :
    1 = App1value
    2 = App3value

Application.Contents.RemoveAll Method

Application.Contents.RemoveAll Method removes or deletes all item from the Contents collection of Application object..

Syntax:

Contents.RemoveAll(
)

 Or in an ASP file.  Imply

<% Application.Contents.RemoveAll %>

Parameters:

void

This method has no parameters.

Return Values:

void

This method has no return values.

Remarks:

All items in the Application.Contents collection are removed.

Examples:

  • Use Application.Contents.RemoveAll to remove all items

    ASP script command:

    <%
    Application("App1") = "App1value"
    Application.Contents("App2") = "App2value"
    Application.Contents.Item("App3") = "App3value"
    Response.write "Elements in Application.Contents Collection :<br>"
    For Each element in Application.Contents
    Response.write element & " = " & Application(element) & "<br>"
    Next
    Response.write "<br>"
    Response.write "Elements in Application.Contents Collection :<br>"
    Application.Contents.RemoveAll
    For Each element in Application.Contents
    Response.write element & " = " & Application(element) & "<br>"
    Next
    %>

    HTTP response output:

    Elements in Application.Contents Collection :<br>
    App1 = App1value<br>
    App2 = App2value<br>
    App3 = App3value<br>
    <br>
    Elements in Application.Contents Collection :<br>

    HTML web page ouput:

    Elements in Application.Contents Collection :
    App1 = App1value
    App2 = App2value
    App3 = App3value

    Elements in Application.Contents Collection :

Link:http://output.to/sideway/default.asp?qno=120200043

Abandon / Timeout / SessionID

Session Object

One of the key functions of Session Object is the session control on the server.

Session.Abandon Method

Session.Abandon method abandons or destroys a Session object and all related resources are released after finised processing the current page.

Syntax:

Abandon(
)

 Or in an ASP file. Imply

<% Session.Abandon %>

Parameters:

void

This method has no parameters.

Return Values:

void

This method has no return values. 

Remarks:

By default, the server destroys all session objects when the session is finished or times out. The Session.Abandon method allows the abandon of the current session of  a client by destroying all session object after finished processing the current page. And create a new session object for the subsequent request by same client. All variables and objects will then be stored in this new session object.

In other word, there is always a sesson object for each client. The session.Abandon method only set the flag for the deletion of all current session objects after the completion of all script commands on the current page. Therefore the Abandon method can be placed anywhere before the end of script commands in the same page. And therefore variables stored in the Session object are still available on the same page, but not in any subsequent web pages by the same client.

Examples:

  • Use Session.Abandon to destroy the session objects

    ASP script command:

    ----Current Page----
    <%
    Session.Abandon
    Session("App") = "Page1value" 
    Response.write Session("App")
    %>

    HTTP response output:

    Page1value

    HTML web page ouput:

    Page1value

    ASP script command:

    ----Subsequent Page----
    <%
    Response.write "New Session: " & Session("App")
    %>

    HTTP response output:

    New Session:

    HTML web page ouput:

    New Session:

Session.Timeout Property

Session.Timeout property sets the length of time out period for the Session object of the application that allowing the client to refresh or request a page on the server before the end of session on the server.

Syntax:

Session.Timeout [=nMinutes]

 Or in an ASP file. Imply

<% Session.Timeout [=nMinutes]  %>

Parameters:

nMinutes

The parameter "nMinutes" is used to specify the allowed idle time, in minutes, of a session before the server terminates the session automatically. The default value is 10 minutes.

Remarks:

The Session.Timeout is related to the idle time of the client when the user does not refresh or request a page.

There is no hard-coded limit on the value of Session.Timeout. The value can be set to 8 minutes or less. It should not be set too low, i.e. lower than 4 minutes because clients rarely respond within that time resulting in a loss of session state. It should also not be set too high, i.e. higher than 20 minutes escept in some special cases because every open session is holding onto memory.

But in IIS 6.0, the minimum allowed value is 1 minute and the maximum is 1440 minuites.

Examples:

  • Use Session.Timeout to specify the allowered idle time of a session

    ASP script command:

    ----Current Page----
    <%
    Session.Timeout=1
    Response.write Session.Timeout & "<br>"
    Session("App") = "Page1value" 
    Response.write Session("App")
    %>

    HTTP response output:

    1<br>
    Page1value

    HTML web page ouput:

    1
    Page1value

    ASP script command:

    ----Subsequent Page after 1 minute----
    <%
    Response.write "New Session: " & Session("App")
    %>

    HTTP response output:

    New Session:

    HTML web page ouput:

    New Session:

Session.SessionID Property

Session.SessionID property returns the unique of LONG data type session identifier generated by the server during the creation of the new session..

Syntax:

Session.SessionID

 Or in an ASP file.  Imply

<% Session.SessionID  %>

Parameters:

void

This method has no parameters.

Remarks:

Although the SessionID is a unique number on the running Web server. Some of the SessionID value may be the same as those SessionID generated before the web server stopped. Therefore SessionID property can not be used to generate the primary key values for an application.

Examples:

  • Use Session.Timeout to specify the allowered idle time of a session

    ASP script command:

    <%
    Response.write Session.SessionID
    %>

    HTTP response output:

    123456789

    HTML web page ouput:

    123456789

Link:http://output.to/sideway/default.asp?qno=120200044

CodePage

Session Object

Another important function of Session object is the control of ASP engine for the HTML output.

Session.CodePage Property

Response.CodePage property Add or set the CodePage for data in the intrinsic objects within the entire session.

Syntax:

Session.CodePage(=CodePageID)

 Or in an ASP file. Imply

<% Response.CodePage(=CodePageID) %>

Parameters:

CodePageID

The parameter "CodePageID" is the page code to represent the character code formatting used for the HTML output. The data type of "CodePageID" is integer. The possible CodePageID are

Family
Code Page
Code Page Charset
1256 708 Arabic (ASMO 708); ASMO-708
720 Arabic (DOS); DOS-720
28596 Arabic (ISO); iso-8859-6
10004 Arabic (Mac); x-mac-arabic
1256 Arabic (Windows); windows-1256
1257 775 Baltic (DOS); ibm775
28594 Baltic (ISO); iso-8859-4
1257 Baltic (Windows); windows-1257
1250 852 Central European (DOS); ibm852
28592 Central European (ISO); iso-8859-2
10029 Central European (Mac); x-mac-ce
1250 Central European (Windows); windows-1250
870 IBM EBCDIC (Multilingual Latin-2); CP870
936 51936 Chinese Simplified (EUC); EUC-CN
936 Chinese Simplified (GB2312); gb2312
52936 Chinese Simplified (HZ); hz-gb-2312
10008 Chinese Simplified (Mac); x-mac-chinesesimp
50935 IBM EBCDIC (Simplified Chinese); x-EBCDIC-SimplifiedChinese
950 950 Chinese Traditional (Big5); big5
20000 Chinese Traditional (CNS)/x-Chinese-CNS
20002 Chinese Traditional (Eten); x-Chinese-Eten
10002 Chinese Traditional (Mac); x-mac-chinesetrad
50937 IBM EBCDIC (Traditional Chinese); x-EBCDIC-TraditionalChinese
1251 866 Cyrillic (DOS); cp866
28595 Cyrillic (ISO); iso-8859-5
20866 Cyrillic (KOI8-R); koi8-r
21866 Cyrillic (KOI8-U); koi8-u
10007 Cyrillic (Mac); x-mac-cyrillic
1251 Cyrillic (Windows); windows-1251
20880 IBM EBCDIC (Cyrillic Russian); x-EBCDIC-CyrillicRussian
21025 IBM EBCDIC (Cyrillic Serbian-Bulgarian); x-EBCDIC-CyrillicSerbianBulgarian
1252 29001 Europa; x-Europa
20106 German (IA5); x-IA5-German
20277 IBM EBCDIC (Denmark-Norway); x-EBCDIC-DenmarkNorway
1142 IBM EBCDIC (Denmark-Norway-Euro); x-ebcdic-denmarknorway-euro
20278 IBM EBCDIC (Finland-Sweden); x-EBCDIC-FinlandSweden
1143 IBM EBCDIC (Finland-Sweden-Euro); x-ebcdic-finlandsweden-euro
1147 IBM EBCDIC (France-Euro); x-ebcdic-france-euro
20273 IBM EBCDIC (Germany); x-EBCDIC-Germany
1141 IBM EBCDIC (Germany-Euro); x-ebcdic-germany-euro
20871 IBM EBCDIC (Icelandic); x-EBCDIC-Icelandic
1149 IBM EBCDIC (Icelandic-Euro); x-ebcdic-icelandic-euro
1148 IBM EBCDIC (International-Euro); x-ebcdic-international-euro
20280 IBM EBCDIC (Italy); x-EBCDIC-Italy
1144 IBM EBCDIC (Italy-Euro); x-ebcdic-italy-euro
20284 IBM EBCDIC (Spain); X-EBCDIC-Spain
1145 IBM EBCDIC (Spain-Euro); x-ebcdic-spain-euro
20285 IBM EBCDIC (UK); x-EBCDIC-UK
1146 IBM EBCDIC (UK-Euro); x-ebcdic-uk-euro
37 IBM EBCDIC (US-Canada); ebcdic-cp-us
1140 IBM EBCDIC (US-Canada-Euro); x-ebcdic-cp-us-euro
861 Icelandic (DOS); ibm861
10079 Icelandic (Mac); x-mac-icelandic
28605 Latin 9 (ISO); iso-8859-15
20108 Norwegian (IA5); x-IA5-Norwegian
437 OEM United States; IBM437
20107 Swedish (IA5); x-IA5-Swedish
20127 US-ASCII; us-ascii
850 Western European (DOS); ibm850
20105 Western European (IA5); x-IA5
28591 Western European (ISO); iso-8859-1
10000 Western European (Mac); macintosh
1252 Western European (Windows); Windows-1252
1253 737 Greek (DOS); ibm737
28597 Greek (ISO); iso-8859-7
10006 Greek (Mac); x-mac-greek
1253 Greek (Windows); windows-1253
869 Greek, Modern (DOS); ibm869
875 IBM EBCDIC (Greek Modern); x-EBCDIC-GreekModern
20423 IBM EBCDIC (Greek); x-EBCDIC-Greek
1255 862 Hebrew (DOS); DOS-862
38598 Hebrew (ISO-Logical); iso-8859-8-i
28598 Hebrew (ISO-Visual); iso-8859-8
10005 Hebrew (Mac); x-mac-hebrew
1255 Hebrew (Windows); windows-1255
20424 IBM EBCDIC (Hebrew); x-EBCDIC-Hebrew
1256 20420 IBM EBCDIC (Arabic); x-EBCDIC-Arabic
932 50930 IBM EBCDIC (Japanese and Japanese Katakana); x-EBCDIC-JapaneseAndKana
50939 IBM EBCDIC (Japanese and Japanese-Latin); x-EBCDIC-JapaneseAndJapaneseLatin
50931 IBM EBCDIC (Japanese and US-Canada); x-EBCDIC-JapaneseAndUSCanada
20290 IBM EBCDIC (Japanese katakana); x-EBCDIC-JapaneseKatakana
51932 Japanese (EUC); euc-jp
50220 Japanese (JIS); iso-2022-jp
50222 Japanese (JIS-Allow 1 byte Kana - SO/SI); iso-2022-jp
50221 Japanese (JIS-Allow 1 byte Kana); csISO2022JP
10001 Japanese (Mac); x-mac-japanese
932 Japanese (Shift-JIS); shift_jis
949 50933 IBM EBCDIC (Korean and Korean Extended); x-EBCDIC-KoreanAndKoreanExtended
20833 IBM EBCDIC (Korean Extended); x-EBCDIC-KoreanExtended
949 Korean; ks_c_5601-1987
51949 Korean (EUC); euc-kr
50225 Korean (ISO); iso-2022-kr
10003 Korean (Mac); x-mac-korean
874 20838 IBM EBCDIC (Thai); x-EBCDIC-Thai
874 Thai (Windows); windows-874
1254 1026 IBM EBCDIC (Turkish Latin-5); CP1026
20905 IBM EBCDIC (Turkish); x-EBCDIC-Turkish
28593 Latin 3 (ISO); iso-8859-3
857 Turkish (DOS); ibm857
28599 Turkish (ISO); iso-8859-9
10081 Turkish (Mac); x-mac-turkish
1254 Turkish (Windows); windows-1254
57006 57006 ISCII Assamese; x-iscii-as
57003 57003 ISCII Bengali; x-iscii-be
57002 57002 ISCII Devanagari; x-iscii-de
57010 57010 ISCII Gujarathi; x-iscii-gu
57008 57008 ISCII Kannada; x-iscii-ka
57009 57009 ISCII Malayalam; x-iscii-ma
57007 57007 ISCII Oriya; x-iscii-or
57011 57011 ISCII Panjabi; x-iscii-pa
57004 57004 ISCII Tamil; x-iscii-ta
57005 57005 ISCII Telugu; x-iscii-te
1361 1361 Korean (Johab); Johab
1200 1200 Unicode; unicode
1201 Unicode (Big-Endian); unicodeFFFE
65000 Unicode (UTF-7); utf-7
65001 Unicode (UTF-8); utf-8
1258 1258 Vietnamese (Windows); windows-1258
50000 50000 User Defined; x-user-defined
932 50932 Japanese (Auto-Select)
50001 50001 Auto-Select
949 50949 Korean (Auto-Select)

Remarks:

The Session.CodePage property is used to specify CodePage of the body content of pages in a session.

Each output body content should have only one character set, otherwire the displayed characters will be incorrect. For each character set, there is a corresponding code page to represent the character code encoded in the intrinsic objects.

And therefore there is always a code page for every response body output. If Response.CodePage is not explicitly set in a page, the value of CodePage for the page should be determined from other settings.

If sessions are enabled, the Response.CodePage can then be implicitly set by the Session.CodePage.

If sessions are not enabled and the @CodePage is present in the ASP file, the Response.CodePage can then be set by the  @CodePage.

If the @CodePage is not present in the ASP file, the Response.CodePage can then be set by the ASPCodePage metabase property.

If the ASPCodePage metabase property is also not set or is set to 0, the Response.CodePage is then set by the system ANSI code page.

In  IIS 5.0 later, Session.CodePage is no longer implicitly set by @CodePage as before. The change was made because @CodePage and Response.CodePage affect only single responses, and Session.CodePage affects all responses in a session. while @CodePage could change the code page for an entire session in IIS 5.0 and eariler version.

In the case, the code page is set explicitly in two pages or in two different response outputs with one response output is called by the other response output, through #include, Server.Execute, or Server.Transfer, usually the code page of the child response output will be set by the parent response output. However if a Response.CodePage is explicitly set in the parent page of a Server.Execute call, an   @CodePage command in the child page will override the parent code page.

So, the explicit setting of  Response.CodePage or Session.CodePage for nonliteral strings should be set before senting the output to the client.

Besides the encoding of the response output of nonliteral strings in the intrinsic objects, the encoding of the literal strings in a script are still set by the @CodePage if present, the AspCodePage metabase property value if set, or the system ANSI code page with the same priority as for intrinsic objects.

Therefore, when both literal and nonliteral strings are used in the same page, the code page setting by @CodePage should match with the code page setting by Response.CodePage, or the page will display incorrectly because the literal strings are encoded differently from the nonliteral strings in the response output.

Since the system default code page will be used when there is no code page setting in a web page, sometimes it is not necessary to set a code page in the web page for those web client with matched system default code page. However, setting the code page for a web page is alway necessary for encoding the response output correctly for all web client in the WWW.n the WWW.

And therefore if the code page is set in a page, the Response.Charset should also be set in order to ensure the response output is displayed correctly for all web client in the WWW.

In order to make the response output display correctly, the file format of a web page must be stored with the same @CodePage setting used in the page. In window, notepad can save files in UTF-8 format or in the system ANSI format. Therefore the ASP file should be saved in UTF-8 format if the @CodePage is set to 65001. Since notepad can save files in system ANSI format according to the default system locale setting in the Regional and Language Options in the Control Panel, notepad can save file in different file format according to @CodePage setting by changing the system locale setting before saving the file.

Similarly, in order to test web pages that use different code pages and character sets in a client computer, the corresponding language packs should also be installed through the adding of language packs in the Regional and Language Options in the Control Panel.

Examples:

  • Response.CodePage with value "65001" with @CodePage=65001 and Response.CharSet with value "utf-8",  and the ASP file is saved in utf-8 format.

    ASP script command:

    <%= "Session.CodePage: " & Session.CodePage & "<br>" %>
    <%= "Response.CodePage: " & Response.CodePage & "<br>" %>
    <%="Welcome in English<br />"%>
    <%="Bienvenue in French<br />"%>
    <%="Recepción in Spanish<br />"%>
    歡迎 in Traditional Chinese<br />
    欢迎 in Simplified Chinese

    HTTP response output:

    Session.CodePage: 65001<br />
    Response.CodePage: 65001<br />
    Welcome in English<br />
    Bienvenue in French<br />
    Recepción in Spanish<br />
    歡迎 in Traditional Chinese<br />
    欢迎 in Simplified Chinese

    HTML web page ouput:

    Session.CodePage: 65001
    Response.CodePage: 65001
    Welcome in English
    Bienvenue in French
    Recepción in Spanish
    歡迎 in Traditional Chinese
    欢迎 in Simplified Chinese

Previous Month  FEB  2012  Next Month
SMTWTFS
1234
567891011
12131415161718
19202122232425
26272829

Previous Month  JUL  2014  Next Month
SMTWTFS
12345
6789101112
13141516171819
20212223242526
2728293031

Sideway BICK Blog

12/02


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013