ASP.NET state service isn’t working in .NET6

Rameil, Eric 21 Reputation points
2022-07-25T09:34:11.973+00:00

We’ve used the ASP.NET state service to handle sessions of our two webservers behind the loadbalancer. After changing .net6 it seems that this function isn’t working anymore. What is the solution in .NET6 to handle these sessions properly?

Developer technologies ASP.NET ASP.NET Core
Developer technologies C#
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-07-26T15:35:38.427+00:00

    the session cookie, like the authentication cookie uses encryption. your servers need to use the same key. in 4.8 you specified the same key in the web.config (machine key). with .net core, the key is always generated, so you need to define a common Store for Data Protection Services:

    https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-6.0


2 additional answers

Sort by: Most helpful
  1. Sreeju Nair 12,666 Reputation points
    2022-07-25T09:40:31.787+00:00

    ASP.Net Core support Session State. Refer the below documentation

    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-6.0#session-state

    Hope this helps


  2. Rameil, Eric 21 Reputation points
    2022-07-25T11:16:15.96+00:00

    Thanks for your answer.
    To make it more clear:

    We migrated a .NET 4.8 WebProject to .NET 6, we are using for authification with Entity Framwork, MySQL database as database and the webserver is hosted on IIS 10. The login is not saved anymore between the two webservers. Before we used the ASP.NET State Service for exchange the session of login between both webservers. Therefor we added the necessary configs to the WebConfig file, this file is not longer existing in .NET 6 projects.

    We allready read the documentation you have given. We tried to use the MSSQL Server as distributed cache, for manually setting session variables this worked fine, but the login is still not possible with the distributed sql server.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.