How to write a HttpModule to replace built-in Session?

D

Danny W

Hi There!

Is it possible to use HttpModule to replace the built-in ASP.NET Session
object? I want to write a HttpModule that will handle storing and retrieving
of session values from an external database.

For example, when a page set values to Session object such as
Session("somevar")=1 then I want my HttpModule to get notified and store the
value into the external database. The same for "getting" the variable, I
want my own HttpModule to retrieve the values from the database.

Any pointers to code samples or tutorials are much appreciated.

Dan
 
H

Hans Kesting

Danny said:
Hi There!

Is it possible to use HttpModule to replace the built-in ASP.NET
Session object? I want to write a HttpModule that will handle storing
and retrieving of session values from an external database.

For example, when a page set values to Session object such as
Session("somevar")=1 then I want my HttpModule to get notified and
store the value into the external database. The same for "getting"
the variable, I want my own HttpModule to retrieve the values from
the database.
Any pointers to code samples or tutorials are much appreciated.

Dan

What is wrong (read: why do you want something different) with storing
the session-state in sqlserver, which is already supported?

By the way: It's not an "HttpModule", as those handle incoming requests.

Hans Kesting
 
D

Danny W

Hi Hans,

Well, I do not have SQL Server and I do not have enough $$$ to buy one.
Besides, creating your own gives you more control and flexibility you need.

Any help on my question? :)

Cheers,
Dan
 
G

Guest

I never try to do this but, I think you must :

1 /
remove the default session state module in the configuration file
add your own session state module

<httpModules>
<add type="Foo.MySessionState" name="MySession"/>
<remove name="Session"/>
</httpModules>

2 / Create your own SessionState module by implementing the IHttpModule
interface. I suggest you to use Reflector to see default session state (class
SessionStateModule) management.
 
B

bruce barker

you can use the free version of sqlserver (msde). the session manager just
calls two procs, so you can easily change them.

-- bruce (sqlwork.com)



| Hi Hans,
|
| Well, I do not have SQL Server and I do not have enough $$$ to buy one.
| Besides, creating your own gives you more control and flexibility you
need.
|
| Any help on my question? :)
|
| Cheers,
| Dan
|
| | > Danny W wrote:
| >> Hi There!
| >>
| >> Is it possible to use HttpModule to replace the built-in ASP.NET
| >> Session object? I want to write a HttpModule that will handle storing
| >> and retrieving of session values from an external database.
| >>
| >> For example, when a page set values to Session object such as
| >> Session("somevar")=1 then I want my HttpModule to get notified and
| >> store the value into the external database. The same for "getting"
| >> the variable, I want my own HttpModule to retrieve the values from
| >> the database.
| >> Any pointers to code samples or tutorials are much appreciated.
| >>
| >> Dan
| >
| > What is wrong (read: why do you want something different) with storing
| > the session-state in sqlserver, which is already supported?
| >
| > By the way: It's not an "HttpModule", as those handle incoming requests.
| >
| > Hans Kesting
| >
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top