Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 987167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:26:14+00:00 2026-05-16T05:26:14+00:00

I’m working on an asp.net project that uses an in-house developed custom SessionStateProvider class.

  • 0

I’m working on an asp.net project that uses an in-house developed custom SessionStateProvider class.

Evidently, the Session_OnStart event is not firing. I have code in Global.asax to handle the event. I can only get this code to execute by changing the Web.config to use the default SessionStateProvider.

What must I do to make my Session_OnStart code execute when I’m using a custom SessionStateProvider class? I have access to the source code.

Update: It clearly says on MSDN that ordinarily, Session_OnStart only fires when the Session mode is InProc, so I’m going to have to do something special to get this wired up the way I want it.

My session state configuration in web.config looks like this:

< sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom"  
 customProvider="ProgramSessionStateProvider"  
 sessionIDManagerType="SessionIDManager.ProgramSessionIDManager"  
sqlConnectionString="SqlSessionServices" cookieName="smartSessionID" >
< providers >
            < add name="ProgramSessionStateProvider"   
type="SessionStateProvider.ProgramSessionStateProvider"   
connectionStringName="SqlSessionServices" writeExceptionsToEventLog="false" / >  
        < /providers >
    < /sessionState >

Update again: I found something interesting this morning. After reading Chris’s answer, I tried using just the customer SessionStateProvider and removed the code for the custom SessionIDManager. Once I did that, I was immediately able to see the Session_OnStart method execute. The problem is, my custom SessionStateProvider requires a custom SessionIDManager. Where exactly is the Session_OnStart event fired from? It looks like it has to do with the SessionIDManager, not the SessionStateProvider.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:26:15+00:00Added an answer on May 16, 2026 at 5:26 am

    A second answer dealing with custom SessionStateStores. On looking at the code I could see no reason why it wouldn’t call session start so I tried to create my own compliant but non-functional session state provider to see what was going on. With my session state provider it called the Session_start in global.asax fine. I include my code as a demo proof of concept:

    Session State Provider:

    namespace WebApplication1
    {
        public class SessionStateProvider : System.Web.SessionState.SessionStateStoreProviderBase
        {
            public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout)
            {
                ISessionStateItemCollection foo = new SessionStateItemCollection();
                HttpStaticObjectsCollection bar = new HttpStaticObjectsCollection();
                return new SessionStateStoreData(foo, bar, 300);
            }
            public override void CreateUninitializedItem(HttpContext context, string id, int timeout){}
            public override void Dispose() { }
            public override void EndRequest(HttpContext context) { }
            public override SessionStateStoreData GetItem(HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
            {
                locked = false;
                lockAge = TimeSpan.FromSeconds(10);
                lockId = new object();
                actions = SessionStateActions.None;
                ISessionStateItemCollection foo = new SessionStateItemCollection();
                HttpStaticObjectsCollection bar = new HttpStaticObjectsCollection();
                return new SessionStateStoreData(foo, bar, 300);
            }
            public override SessionStateStoreData GetItemExclusive(HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
            {
                locked = false;
                lockAge = TimeSpan.FromSeconds(10);
                lockId = new object();
                actions = SessionStateActions.None;
                ISessionStateItemCollection foo = new SessionStateItemCollection();
                HttpStaticObjectsCollection bar = new HttpStaticObjectsCollection();
                return new SessionStateStoreData(foo, bar, 300);
            }
            internal virtual void Initialize(string name, NameValueCollection config, IPartitionResolver partitionResolver) { }
            public override void InitializeRequest(HttpContext context) { }
            public override void ReleaseItemExclusive(HttpContext context, string id, object lockId) { }
            public override void RemoveItem(HttpContext context, string id, object lockId, SessionStateStoreData item) { }
            public override void ResetItemTimeout(HttpContext context, string id) { }
            public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { }
            public override bool SetItemExpireCallback(SessionStateItemExpireCallback expireCallback){return true;}
        }
    }
    

    Global.asax:

        protected void Session_Start(object sender, EventArgs e)
        {
            throw new Exception("It worked!");
        }
    

    web.config:

        <sessionState mode="Custom" customProvider="MySessionProvider">
            <providers>
                <add name="MySessionProvider" type="WebApplication1.SessionStateProvider"/>
            </providers>
        </sessionState>
    

    The point of this post is mainly to say that if you are using the provided session management module, even with a custom provider it should still fire off the session_start event. Perhaps you can try with my dummy state provider and see if that fires off your event. Also I assume that the signature of your session_onstart is actually correct? (ie no paramaters or (object,eventargs) ).

    Currently we are at a duff position because all the information we have so far is along the wrong lines. We are now left with either something about your sessionstateprovider is causing the session_start not to fire or something about the rest of your code is. Using my dummy should help us answer that question (I hope).

    For what its worth the session_start event should get fired just after the CreateNewStoreData method has run in your provider class so you can try putting in a breakpoint there and just seeing where it does head to after that method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.