TsgcWebSocketHTTPServerProperties › SessionClass

SessionClass Property

サーバーが新しい HTTP セッションを作成する際に使用するクラス。セッションごとのカスタムデータを保存するには、独自の TIdHTTPSession 派生クラスに設定してください。

構文

property SessionClass: TsgcIdHTTPSessionClass read GetSessionClass write SetSessionClass;
// TsgcIdHTTPSessionClass = class of TIdHTTPSession

デフォルト値

TIdHTTPSession

解説

By default the server creates plain TIdHTTPSession objects. Set SessionClass to a descendant of TIdHTTPSession and the server will create that class instead, for every session, including the ones created automatically when AutoStartSession is enabled. The unique session ID, the session cookie, SessionTimeOut and the removal of stale sessions keep working exactly as before.

セッションが作成されたときに独自のフィールドを初期化したい場合は、派生クラスで仮想コンストラクタ CreateInitialized をオーバーライドしてください。セッションは ARequestInfo.Session から読み戻し、自分のクラスにキャストします。

SessionClassは、サーバーがアクティブ化されるに設定しておく必要があり、nil にすることはできません。独自のSessionListを割り当てた場合、どのクラスを作成するかは自分のリストが決めるため、このプロパティはもはや適用されません。詳しい説明はSessionsを参照してください。また、OnCreateSessionイベントはセッションクラスを変更するための推奨方法ではないことに注意してください。

使用例


type
  TMySession = class(TIdHTTPSession)
  private
    FUserName: String;
  public
    property UserName: String read FUserName write FUserName;
  end;

oServer := TsgcWebSocketHTTPServer.Create(nil);
oServer.SessionState := true;
oServer.SessionTimeout := 600000;
oServer.SessionClass := TMySession;
oServer.Active := true;

プロパティに戻る