Skip to content

SqlSessionStateProviderAsync Session Id changes on App Service Slot Swap (Everyone gets logged out) #96

@robs

Description

@robs

I'm raising this because I spent hours and hours down Machine Key related rabbit holes and am hoping to save anyone else the joy of that :)

The long and short of it is that:

  1. AppId isn't settable via any config option, it only ever uses the static HttpRuntime.AppDomainAppId
  2. GetHashCode doesn't always return the same value for a given string so even if you set HttpRuntime.AppDomainAppId via reflection, the value from GetHashCode() still changes.

This is where the session id is suffixed with HttpRuntime.AppDomainAppId.GetHashCode().ToString("X8", CultureInfo.InvariantCulture)
https://github.com/aspnet/AspNetSessionState/blob/06de5f5270c6d9b7d7f6bd1a0bc6343b8c0a56f5/src/SqlSessionStateProviderAsync/SqlSessionStateProviderAsync.cs#L128C77-L128C77

I'm not sure what the proper resolution is but setting HttpRuntime.AppDomainAppId (via reflection) at start up and just appending the AppId string without the call to GetHashCode.ToString(X8) means that the session id doesn't change across slot swaps.

Happy to provide any other info if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions