MongoDB-ASP.NET-Session-State-Store
MongoDB-ASP.NET-Session-State-Storeとは、MongoDBにセッション情報を保持するASP.NETのセッションプロバイダーである[1]。
目次
概要
Redis関連のセッションプロバイダーを色々試みたがMonoでの動作が不安定だったので諦めてこちらを利用してみた。 Redisほどの速度は期待できないものの少し試した限りでは安定しているようである。 MongoDBの冗長化関連の機能は特筆すべきものがあるのでもう少し検証してみようと思う。
インストール
NuGetから入れる。
Web.configにConnectionStringを設定する。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- 抜粋 -->
<connectionStrings>
<add name="MongoSessionServices" connectionString="mongodb://localhost"/>
</connectionStrings>
<!-- 抜粋 -->
</configuration>
Web.configにセッションプロバイダーを設定する。 ここで指定したDBは無ければ勝手に作られる模様。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- 抜粋 -->
<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" />
</providers>
</sessionState>
</system.web>
<!-- 抜粋 -->
</configuration>
おわり