Skip to content

Web.config parameters

Marc edited this page Jan 23, 2016 · 10 revisions

Parameters detail

Following you have a XML that sets all parameters to the default value. Next the description of all of them:

    <system.web>
    (...)
    <sessionState mode="Custom" customProvider="MongoSessionStateProvider">
      <providers>
        <add name="MongoSessionStateProvider"
             type="MongoSessionStateStore.MongoSessionStateStore"
             connectionStringName="MongoSessionServices"
             maxUpsertAttempts="220"
             msWaitingForAttempt="500"
             AutoCreateTTLIndex="true"
             WriteConcern="W1"
             Journal="false"
             BSONDefaultSerialize="true"
             databaseName="SessionState2"
             collectionName="Sessions2" 
             SerializationType="BSON"
             applicationName="ApplicationName" />
      </providers>
    </sessionState>
    (...)
    </system.web>

Please note:

  • Parameter names are not case sensitive.

##SerializationType (added in v3.2.0) Type of serialization used to serialize the session data. The allowed values are: "BSON" or "RAW".
For further detail of both types of serialization read this document.

  • Default value: BSON.
  • Required: no.

name

The name of the session state provider.

  • Default value: "MongoSessionStateProvider".
  • Required: yes.

type

The full name of the type (namespace + class) that implements the provider. Is not recommended to change this value unless if you adapt the implementation by your own.

  • Default value: "MongoSessionStateStore.MongoSessionStateStore".
  • Required: yes.

connectionStringName

The connection string name defined in the connectionStrings section.

  • Default value: "MongoSessionServices".
  • Required: yes.

maxUpsertAttempts

Is the max number of attempts that will try to send an upsert to a replicaSet in case of primary elections. This parameter is used in combination with msWaitingForAttempt parameter.

  • Default value: 220.
  • Required: no.

msWaitingForAttempt

Is the time in milliseconds that the session provider will wait in each retry when MongoDB is unavailable. This could occurs in a replica set election process and other cases. If you are not working in a replica set environment the pause and retry attempts will produce by the same way, giving the opportunity to do some short administration tasks in a single server (i.e. server restart).

  • Default value: 500.
  • Required: no.

Please note: The combination of maxUpsertAttempts and msWaitingForAttempt will define the max amount of time that one client request can be alive in the server. The default value for executionTimeout parameter in ASP.NET application is 110 seconds. So if we retry each 500 milliseconds during 220 retries means that we'll be retrying during 110 seconds. If you have an executionTimeout different than the default value you should adapt this two parameters properly to cover the max amount of execution time as possible. In a normal situation the election process in a Replica Set should take a few seconds to elect a new primary, but could take more than 60 seconds if there are problems (network, process overload, etc.)

AutoCreateTTLIndex

If true creates a TTL index (time to live index). The value of the time to live is taken from Session.Timeout value.

The index is created in the Sessions collection when session state provider is initialized. If the index is already created it will do nothing. Is strongly recommended to have this parameter set to true in order of to have the session collection as clean as possible.

If you want to make SessionState with no expiration time set this parameter to false. In this case Session.Timeout value won't have any effect.

  • Default value: true.
  • Required: no.

WriteConcern

Sets the write concern used in all mongoDB data requests. The allowed values are "W1", "W2", "W3", "W4" and "WMAJORITY".

  • Default value: "W1".
  • Required: no.

Points to consider:

  • Until version v2.0.2 (included) a value of true in Journal parameter disables this setting.
  • If you establish too high value could cause a general application lock.
  • The default value ("W1") is the recommended value for this scenario.
  • Performance could decrease as higher is the value.
  • The "Unacknowledged" value is not allowed because is an inappropriate for the purposes of this application and not passes the test cases.

For further information about write concern (also affects the next parameter) see: http://docs.mongodb.org/manual/core/write-concern/

Journal

Specifies if write concern is Journaled or not. Possible values are true or false.

  • Default value: false (recommended).
  • Required: no.

For further information about write concern and journaling read: http://docs.mongodb.org/manual/core/write-concern/#journaled

Please note: Write concern in Journaled mode could affect notably the application performance and is observable with the test cases included in this project. Few scenarios should need this level of write ACK.

Until version v2.0.2 (included) a true value of journaled means that the write concern is always 1 independently of the value set in the parameter WriteConcern.

BSONDefaultSerialize (added in v2.0.0 and removed in v3.0.0)

This parameter is no longer available, was available in versions 2.X.X

This parameter is created for compatibility with v1.0.0. If it's true uses BSON types as a default type for serialization. If false values will be serialized as JSON (the compatibility mode).

  • Default value: true.
  • Required: no.

Please note: The JSON serialization and this parameter will be removed in next versions.

databaseName (added in v2.0.0)

Sets the name of the database used to store session data.

  • Default value: "SessionState".
  • Required: no.

collectionName (added in v2.0.0)

Sets the name of the collection used to store session data.

  • Default value: "Sessions".
  • Required: no.

applicationName (added in v3.1.0)

Sets the application name. This value -in addition with SessionID- is used to generate the _id field of every session document stored in the Sessions collection.

Now you can share the session data across different applications. Please note that, even that it's quite difficult and improbable, a sessionId collision could occur between different applications. Also, in each application you'll must set the same application name in the web.config.

  • Default value: System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath
  • Required: no.