ASP セッション: <session>

概要

<asp> 要素の <session> 要素は、Active Server Pages (ASP) のセッション状態の設定を指定します。 セッション状態は、インターネット インフォメーション サービス (IIS) 7 が一意の各クライアント セッションに関する情報を格納する手段です。 たとえば、Web サイトにショッピング カート アプリケーションがある場合、各クライアントのショッピング カートの内容をセッション状態に格納できます。

ASP のセッション状態を維持するには、サーバーにメモリ リソースが必要です。また、必要なメモリの量は、各セッションに格納する情報の量によって異なります。 IIS 7 で使われるリソースを調整するには、セッション状態の設定を指定できます。 たとえば、max 属性は格納するセッションの最大数を指定し、timeout 属性は各 ASP セッションの継続時間を指定します。

アプリケーションでセッション状態が必要ない場合は、allowSessionState 属性を false に設定すると、ASP のセッション状態は無効になります。

互換性

バージョン メモ
IIS 10.0 <session> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <session> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <session> 要素は、IIS 8.0 では変更されませんでした。
IIS 7.5 <session> 要素は、IIS 7.5 では変更されませんでした。
IIS 7.0 <asp> 要素の <session> 要素は IIS 7.0 で導入されました。
IIS 6.0 <session> 要素は、次の IIS 6.0 メタベース プロパティを置き換えます。
  • AspAllowSessionState
  • AspKeepSessionIDSecure
  • AspSessionMax
  • AspSessionTimeout

段取り

Web サーバーで ASP アプリケーションをサポートおよび構成するには、ASP モジュールをインストールする必要があります。 ASP モジュールをインストールするには、次の手順のようにします。

Windows Server 2012 または Windows Server 2012 R2

  1. タスク バーで [サーバー マネージャー]をクリックします。
  2. [サーバー マネージャー] で、[管理] メニューをクリックし、[役割と機能の追加] をクリックします。
  3. 役割と機能の追加ウィザードで、[次へ] をクリックします。 インストールの種類を選択し、[次へ] をクリックします。 対象サーバーを選択し、[次へ] をクリックします。
  4. [サーバーの役割] ページで、[Web サーバー (IIS)][Web サーバー][アプリケーション開発] の順に展開して、[ASP] を選びます。
    Image of Web Server and Application Development pane expanded with A S P selected.
  5. [ASP に必要な機能を追加しますか?] ダイアログ ボックスが表示されたら、[機能の追加] をクリックします。 (このページは、ISAPI 拡張機能の役割サービスをサーバーにまだインストールしていない場合にのみ表示されます)。
  6. [サーバーの役割] ページで、[次へ] をクリックします。
  7. [機能の選択] ページで、[次へ] をクリックします。
  8. [インストール オプションの確認] ページで、[インストール] をクリックします。
  9. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] をクリックします。

  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。

  3. [インターネット インフォメーション サービス][World Wide Web サービス][アプリケーション開発機能] の順に展開して、[ASP] を選択します。
    Screenshot of Turn Windows on or off feature page with Application Development Features pane expanded and A S P selected.

    Note

    ISAPI 拡張機能の役割がまだインストールされていない場合、それが選択されます。

  4. OK をクリックします。

  5. 閉じるをクリックします。

Windows Server 2008 または Windows Server 2008 R2

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして、[サーバー マネージャー] をクリックします。
  2. [サーバー マネージャー] 階層ウィンドウで [役割] を展開し、[Web サーバー (IIS)] をクリックします。
  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] をクリックします。
  4. 役割サービスの追加ウィザード[役割サービスの選択] ページで、[ASP] を選択します。
    Screenshot of Select Role Services page of the Add Role Services Wizard displaying A S P selected.
  5. [ASP で必要な役割サービスの追加] ダイアログ ボックスが表示されたら、[必要な役割サービスの追加] をクリックします。 (このページは、ISAPI 拡張機能の役割サービスをサーバーにまだインストールしていない場合にのみ表示されます)。
    Screenshot of Add Role Services dialog box displaying the Add role services required for A S P question and Add Required Role Services button.
  6. [役割サービスの選択] ページで、[次へ] をクリックします。
  7. [インストール オプションの確認] ページで、[インストール] をクリックします。
  8. [結果] ページで、 [閉じる]をクリックします。

Windows Vista または Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順にクリックします。
  2. [コントロール パネル][プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。
  3. [インターネット インフォメーション サービス][World Wide Web サービス][アプリケーション開発機能] の順に展開します。
  4. [ASP] を選択して、[OK] をクリックします。
    Screenshot of Turn Windows features on or off page displaying Application Development Features pane expanded and A S P selected.

操作方法

サイトまたはアプリケーションの ASP セッション状態の設定を構成する方法

  1. インターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー][ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
      • [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーの [スタート] をクリックし、[管理ツール] をポイントして、[インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順にクリックします。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウで、サーバー名を展開して [サイト] を展開し、構成する Web サイトまたは Web アプリケーションに移動します。

  3. サイト、またはアプリケーションの [ホーム] ウィンドウで、[ASP] をダブルクリックします。
    Screenshot pf application Home pane displaying A S P highlighted.

  4. [ASP] ウィンドウで、[セッションのプロパティ] セクションを展開して、目的の設定を構成します。
    Image of A S P pane with Session Properties section expanded and highlighted.

  5. [操作] ウィンドウで [適用] をクリックします。

構成

属性

属性 説明
allowSessionState 省略可能な Boolean 属性です。

ASP アプリケーションのセッション状態の永続化を有効にするかどうかを指定します。

既定値は true です。
keepSessionIdSecure 省略可能な Boolean 属性です。

セキュリティ保護されたセッション チャネル経由で割り当てられている場合に、セッション ID をセキュリティ保護された Cookie として送信するかどうかを指定します。

既定値は true です。
max 省略可能な uint 属性。

同時セッションの最大数を指定します。

既定値は 4294967295 です。
timeout 省略可能な timeSpan 属性。

セッション オブジェクトに関連付けられた最後の要求が行われた後で、そのオブジェクトを保持する最大時間 (hh:mm:ss) を指定します。

既定値は 00:20:00 です。

子要素

なし。

構成サンプル

次の構成サンプルでは、ASP のセッション状態を有効にし、ASP セッションの最大数を 1000 に設定し、既定の Web サイトのセッション タイムアウトを 10 分に設定します。

<location path="Default Web Site">
   <system.webServer>
      <asp>
         <session allowSessionState="true" max="1000" timeout="00:10:00" />
      </asp>
   </system.webServer>
</location>

サンプル コード

次のコード サンプルでは、ASP のセッション状態を有効にし、ASP セッションの最大数を 1000 に設定し、既定の Web サイトのセッション タイムアウトを 10 分に設定します。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/asp /session.allowSessionState:"True" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/asp /session.max:"1000" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/asp /session.timeout:"00:10:00" /commit:apphost

Note

AppCmd.exe を使用してこれらの設定を構成する場合は、commit パラメーターを必ず apphost に設定する必要があります。 これにより、ApplicationHost.config ファイルの適切な location セクションに構成設定がコミットされます。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection aspSection = config.GetSection("system.webServer/asp", "Default Web Site");

         ConfigurationElement sessionElement = aspSection.GetChildElement("session");
         sessionElement["allowSessionState"] = true;
         sessionElement["max"] = 1000;
         sessionElement["timeout"] = TimeSpan.Parse("00:10:00");

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim aspSection As ConfigurationSection = config.GetSection("system.webServer/asp", "Default Web Site")

      Dim sessionElement As ConfigurationElement = aspSection.GetChildElement("session")
      sessionElement("allowSessionState") = True
      sessionElement("max") = 1000
      sessionElement("timeout") = TimeSpan.Parse("00:10:00")

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var aspSection = adminManager.GetAdminSection("system.webServer/asp", "MACHINE/WEBROOT/APPHOST/Default Web Site");

var sessionElement = aspSection.ChildElements.Item("session");
sessionElement.Properties.Item("allowSessionState").Value = true;
sessionElement.Properties.Item("max").Value = 1000;
sessionElement.Properties.Item("timeout").Value = "00:10:00";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set aspSection = adminManager.GetAdminSection("system.webServer/asp", "MACHINE/WEBROOT/APPHOST/Default Web Site")

Set sessionElement = aspSection.ChildElements.Item("session")
sessionElement.Properties.Item("allowSessionState").Value = True
sessionElement.Properties.Item("max").Value = 1000
sessionElement.Properties.Item("timeout").Value = "00:10:00"

adminManager.CommitChanges()