Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
robs opened this issue Jul 21, 2023 · 0 comments · May be fixed by #97
Open

Comments

@robs
Copy link

robs commented Jul 21, 2023

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.

@robs robs linked a pull request Jul 21, 2023 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant