RedisSessionProvider
RedisSessionProvider copied to clipboard
Cast Error when using Trace
Thanks for a great implementation of a Redis Session provider!
I found a bug when Trace is enabled (have it at the application level). In web.config <system.web> <trace enabled="true" requestLimit="90" pageOutput="false" traceMode="SortByTime" localOnly="false" /> </system.web>
Causes this exception Exception: System.InvalidCastException Unable to cast object of type 'System.Collections.Generic.KeyValuePair`2[System.String,System.Object]' to type 'System.String'.
at System.Web.TraceContext.EndRequest() at System.Web.UI.Page.ProcessRequestEndTrace() at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.sobobacasino_default_aspx.ProcessRequest(HttpContext context) in c:\Users\dcate.MARKETMETRIX\AppData\Local\Temp\Temporary ASP.NET Files\root\ec897ff3\55745380\App_Web_qw3cpivu.0.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I can run fine with Trace turned off, but it might be needed from time to time.
Thanks,
- Darryl
Thanks for bringing this to my attention :)
The cause of this issue is that TraceContext expects that HttpSessionState would enumerate strings as described here:
/// <summary>
/// Returns an enumerator that can be used to read all the session-state variable names in the current session.
/// </summary>
///
/// <returns>
/// An <see cref="T:System.Collections.IEnumerator"/> that can iterate through the variable names in the session-state collection.
/// </returns>
public IEnumerator GetEnumerator()
{
return this._container.GetEnumerator();
}
But RedisSessionStateItemCollection in fact falls back to Dictionary<string, object> implementation of GetEnumerator().
I've created a pull request which I think should fix this problem.
Hi welegan! could you please revise the Maksim's fix https://github.com/welegan/RedisSessionProvider/pull/18 once again?
The issue might prevent from using this library in production systems because with RedisSessionProvider this https://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.getenumerator(v=vs.110).aspx is never gonna work. Any access to Page.Session.GetEnumerator() would return enumerator by KeyValuePair, not by string as expected.