views:

57

answers:

1

I'm implementing my own SessionStateStoreProvider with a schemaless database. It's a little hard to tell from the documentation but it seems as though I will have to have a separate process for cleaning up expired sessions since the database will not have a way to notify the session state store that a session has expired.

Am I wrong about this? I haven't seen an alternative example for overriding the SetItemExpireCallback method.

+1  A: 

Yes I believe that is correct.

If you store the sessions on database, then there is a Job on Sql Server Agent thats call this procedure every minute or so:

    DECLARE @now datetime
    SET @now = GETUTCDATE()

    DELETE ASPStateTempSessions WHERE Expires < @now

There is no trigger for session expired. Lets say that was a trigger, where that can be ? There is no place to put that trigger alone to understand that the session expired and auto-delete his self.

From the other hand what you can do, is not to create a timer, but when a user ask for a page, every 1-2 minute, trigger a function to delete the expired ones.

So you make a trigger from a user call, but you must make it run only onces every 1-2 minutes using some kind of lock, and check for the last run.

Hope thats helps.

Aristos