Click here to Skip to main content
15,889,931 members
Articles / Programming Languages / XML
Tip/Trick

How to Implement a Custom Oracle Session Provider

Rate me:
Please Sign up or sign in to vote.
1.57/5 (3 votes)
27 Jun 2008CPOL1 min read 34.6K   1K   19   1
Oracle session provider

Introduction

This tutorial is intended to be a beginner's introduction to custom session providers. Since the introduction of ASP.NET 2.0, Microsoft has allowed you to tap into its session-state store provider via the SessionStateStoreProviderBase class. The session-state store inherits from the abstract SessionStateStoreProviderBase which is made up of the following 12 methods:

  • CreateNewStoreData
  • CreateUninitializedItem
  • Dispose
  • GetItem
  • GetItemExclusive
  • Initialize
  • InitializeRequest
  • ReleaseItemExclusive
  • RemoveItem
  • ResetItemTimeout
  • SetAndReleaseItemExclusive
  • SetItemExpireCallback

You can read more about these methods here.

Issue

One of the requirements of my most recent projects was for session data to be stored in Oracle. While this is relatively easy to implement using the built in SQL server provider, it is less obvious how to do this with Oracle. After an extensive web search, I found little information on this subject. Neither Microsoft nor Oracle provided working examples of using Oracle as your session data store. However, Microsoft did have a decent example on how to implement a custom session provider using an Access database. This example was my starting point, and the basic template I used for this article.

Using the Code

In the Web.config:

  1. Add the Oracle database connection string.
  2. Add the custom s<place w:st="on"><placename w:st="on">ession-s<placetype w:st="on">tate section.
    XML
    <configuration>
       <connectionStrings>
         <add name="COMPANY" connectionString="Data Source=spindev;Persist Security Info=True;
         User ID=username;Password=password;Min Pool Size=3;" 
         providerName="System.Data.OracleClient"/>
       </connectionStrings>
    </configuration>
    
    <system.web>
      <sessionState mode="Custom" customProvider="CustomSessionData" 
      cookieless="false" timeout="1">
        <providers>
          <add name="CustomSessionData" type="CustomSessionData" />
        </providers>
      </sessionState>
    </system.web>
  3. Add the custom OracleSessionProvider to your app_code folder.

Note: At least one session variable must be set for the provider to be initialized.

Summary

I have provided you with an example of the basics of implementing a custom session-state provider using an Oracle DB. There are other issues involved in managing session (i.e., session_end), but this should get you started.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGreat idea but more info? Pin
Chris Maunder28-Jun-08 5:26
cofounderChris Maunder28-Jun-08 5:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.