Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Abstract class: RT.Servers.Session

Summary

Provides functionality to track user sessions in HTTP requests using cookies. See remarks for usage guidelines.

Remarks

Intended use is as follows:

  • Declare a class containing one or more fields which constitute your session data.
  • Derive that class from Session, FileSession, or your own specialization of either.
  • You can now augment any HTTP request handler that looks like this:

    req => { /* code to handle request, no session support */ }

    by changing it into this:

    req => Session.EnableAutomatic<TSession>(req, session => {
        /* code to handle request with session variable available */
    })

    (replace TSession with the name of your derived class; see Session.EnableAutomatic<TSession>(HttpRequest, Func<TSession, HttpResponse>) or Session.EnableManual<TSession>(HttpRequest, Func<TSession, HttpResponse>)).

  • Within your request handler, you can make arbitrary changes to the session object, which will be persisted automatically.
  • If you use Session.EnableManual<TSession>(HttpRequest, Func<TSession, HttpResponse>), Session.SessionModified must be set to true whenever any value in the session object is changed.
  • If you use Session.EnableAutomatic<TSession>(HttpRequest, Func<TSession, HttpResponse>), the session object must implement ISessionEquatable<TSession>. In this case, modifications to the session object are detected by taking a clone of the session object, then running the request handler, and then comparing the two.
  • You can set Session.Action if you want the session reverted or deleted.

Instance methods

void
CleanUp(HttpResponse response, bool wasModified)
  • Virtual
Saves/deletes the session and/or sets the session cookie, as appropriate. Only call this if you are not using Session.EnableAutomatic<TSession>(HttpRequest, Func<TSession, HttpResponse>), Session.EnableManual<TSession>(HttpRequest, Func<TSession, HttpResponse>), SessionExtensions or anything else that already calls it.
string
  • Overrides: object.ToString()
Returns a string representation of this session object.

Static methods

HttpResponse
EnableAutomatic<TSession>(HttpRequest req, Func<TSession, HttpResponse> handler)
Enables the use of sessions in an HTTP request handler. Use this if your session class implements ISessionEquatable<TSession>. If your session class does not have a default constructor, use SessionExtensions.EnableAutomatic<TSession>(this TSession, HttpRequest, Func<TSession, HttpResponse>). (see also remarks)
HttpResponse
EnableManual<TSession>(HttpRequest req, Func<TSession, HttpResponse> handler)
Enables the use of sessions in an HTTP request handler. Use this if your session class does not implement ISessionEquatable<TSession>; your class will have to manually set Session.SessionModified to true before the request handler returns if any change was made to the session. If your session class does not have a default constructor, use SessionExtensions.EnableManual<TSession>(this TSession, HttpRequest, Func<TSession, HttpResponse>). (see also remarks)

Instance properties

SessionActionControls what happens to the session data when the request handler returns.
bool True if a new session was created, or any of the cookie parameters were modified (such as Session.CookieExpires).
stringContains the session ID, which is also the cookie value.
bool True if a new session was created, or any of the session variables were modified. Derived classes should set this to true whenever a session variable is modified. Set this to false to discard all session changes (otherwise they will be saved upon session Session.CleanUp(HttpResponse, bool)).