Click here to Skip to main content
Licence CPOL
First Posted 27 Jun 2008
Views 12,287
Downloads 267
Bookmarked 18 times

How to implement a custom Oracle session provider.

By | 27 Jun 2008 | Article
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 project 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 session-state section.
<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)

About the Author

Rob_Smith_MN



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionGreat idea but more info? PinadminChris Maunder5:26 28 Jun '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 27 Jun 2008
Article Copyright 2008 by Rob_Smith_MN
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid