Friday 29 January 2016

Asp.net sessionID changing for each page request for SQLServer mode.

I am using SQLServer session mode  in my application. All is well eacept extra unwanted entry for each page sessionID in ASPStateTempSessions table.
Suddenly my ASPStateTempSessions count goes up to million and bellion. I am stuck with so huge table where i am unable to perform delete operation
in order to delete expire session with procedure DeleteExpiredSessions.
It becam massive for me to delete all expire and unwanted session from ASPStateTempSessions table.


I went through web and i tried all cookieless="false"/ "true" and regenerateExpiredSessionId="true" / "false".
My config code is

<sessionState allowCustomSqlDatabase="true"  cookieless="false"   mode="SQLServer" sqlCommandTimeout="10" sqlConnectionString="sessionconstr" timeout="60"  />

Finally i solve this all by using some tricks.
I create a trigger in sql server and clearing all Empty SessioID having sessionitemshort=0x3C0000000000FF.
And it worked for me.
No i am not getting too much massive data inside SQL table and sessionID for each page in not tracking.


Create TRIGGER ClearUnwantedSession ON [dbo].[ASPStateTempSessions] 
FOR INSERT
AS
delete  .dbo.ASPStateTempSessions  where sessionitemshort=0x3C0000000000FF;
execute DeleteExpiredSessions
GO