I am working on a prototype program that should test different providers (SessionState, Profile, etc.) for ASP.NET, i.e. MySQL, Oracle, etc. I am currently using the MySQL provider. I just managed to create an instance of the provider, SessionStateContainer and SessionState itself.
Type mySqlType = Type.GetType("MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.6.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d", true, true); SessionStateStoreProviderBase provider = (SessionStateStoreProviderBase)Activator.CreateInstance(mySqlType); System.Collections.Specialized.NameValueCollection providerConfig = new System.Collections.Specialized.NameValueCollection(); providerConfig.Add("connectionStringName", "LocalMySqlServer"); providerConfig.Add("applicationName", "/"); providerConfig.Add("autogenerateschema", "True"); providerConfig.Add("enableExpireCallback", "False"); provider.Initialize("MySqlSessionStateProvider", providerConfig); HttpContext context = new HttpContext( new HttpRequest("fake", "http://localhost:14359", ""), new HttpResponse(new StringWriter())); SessionStateStoreData storeData = provider.CreateNewStoreData(context, 100); System.Web.SessionState.HttpSessionStateContainer sessionStateContainer = new System.Web.SessionState.HttpSessionStateContainer( "mySession", storeData.Items, storeData.StaticObjects, 100, true, System.Web.HttpCookieMode.UseDeviceProfile, SessionStateMode.Custom, false ); Type sessionStateType = Type.GetType("System.Web.SessionState.HttpSessionState, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); HttpSessionState sessionState = (HttpSessionState)sessionStateType .GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(IHttpSessionState) }, null) .Invoke(new object[] { ssessionStateContainer }); provider.InitializeRequest(context);
Everything seems to work fine, as I can write some values ββin the session that I created, and I can read them from there:
sessionStateContainer.Add("SomeKey", "SomeValue"); var test = sessionStateContainer["SomeKey"]; Console.WriteLine("var test: " + test.ToString());
Here is the interesting part - when I check the my_aspnet_sessions table in the database, there is nothing there.
So I wonder where the data was written, or am I doing something wrong?
Update:
Despite the fact that this problem is no longer a blocker, I am still interested to find out, and if someone tries to try, here I used connectionString :
<connectionStrings> <remove name="LocalMySqlServer" /> <add name="LocalMySqlServer" connectionString="server=localhost;database=session_test;User Id=user;password=pass" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
You will also need the MySQL Connector NET .