Skip to content

Commit

Permalink
(asp.net) session_name() gets correct value from web config
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmisek committed Jan 6, 2021
1 parent db0c81c commit 7416187
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Peachpie.RequestHandler/Session/AspNetSessionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ sealed class AspNetSessionHandler : PhpSessionHandler
{
public static readonly PhpSessionHandler Default = new AspNetSessionHandler();

/// <summary>
/// The session item with serialized PHP $_SESSION.
/// </summary>
const string PhpNetSessionVars = "Peachpie.SessionVars";

/// <summary>
Expand Down Expand Up @@ -58,7 +61,7 @@ string EnsureSessionId(HttpContext httpContext)
/// <summary>
/// Gets the session name.
/// </summary>
public override string GetSessionName(IHttpPhpContext webctx) => GetHttpContext(webctx).Session.SessionID;
public override string GetSessionName(IHttpPhpContext webctx) => AspNetSessionHelpers.GetConfigCookieName() ?? AspNetSessionCookieName;

/// <summary>
/// Sets the session name.
Expand All @@ -72,10 +75,7 @@ public override void Abandon(IHttpPhpContext webctx)
GetHttpContext(webctx).Session.Abandon();
}

public override string GetSessionId(IHttpPhpContext webctx)
{
return GetHttpContext(webctx).Session.SessionID;
}
public override string GetSessionId(IHttpPhpContext webctx) => GetHttpContext(webctx).Session.SessionID;

public override PhpArray Load(IHttpPhpContext webctx)
{
Expand Down
23 changes: 23 additions & 0 deletions src/Peachpie.RequestHandler/Session/AspNetSessionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,28 @@ public static void SetContainer(this HttpSessionState state, IHttpSessionState c
s_HttpSessionState_container.SetValue(state, container ?? throw new ArgumentNullException(nameof(container)));
}
}

/// <summary>
/// private static SessionStateSection s_config
/// </summary>
static FieldInfo s_SessionIDManager_config = typeof(SessionIDManager).GetField("s_config", BindingFlags.Static | BindingFlags.NonPublic);

/// <summary>
/// Gets the configured session cookie name, or <c>null</c> if the value cannot be determined.
/// </summary>
/// <returns></returns>
public static string GetConfigCookieName()
{
if (s_SessionIDManager_config != null)
{
var section = s_SessionIDManager_config.GetValue(null) as System.Web.Configuration.SessionStateSection;
if (section != null)
{
return section.CookieName;
}
}

return null;
}
}
}

0 comments on commit 7416187

Please sign in to comment.