Pergunta

I've set up the same site on two servers sitting behind a load balancer. I have the following in my web.config file

<sessionState mode="SQLServer" cookieless="false" allowCustomSqlDatabase="true" 
sqlConnectionString="Data Source=server;Initial Catalog=ASPState;Persist Security 
Info=True;User ID=user;Password=password" timeout="2880" sqlCommandTimeout="10" />

It appears to be working, I can see the ASPState tables populating when I log in, however I see that if I refresh several times after logging in it goes back and forth between being logged in and not logged in depending on which server I hit. Am I missing something?

I'm using the default webmatrix authentication built into MVC 4.

Foi útil?

Solução 2

As this post explains you will need to have the same Application ID on both servers.

"When you create applications that you expect to share session state using Sql Server, they need the same ID configured in IIS. This is because the session ID that is generated is generated based on the application ID. (Internally the application ID is something like LM/W3SVC/1 The two servers had different IDs for each application in IIS. The resolution is to change the ID under `Manage Website -> Advanced Settings' on each server."

Cheers

Outras dicas

This ca be because you have different MachineKeys on your servers or the have the default value. And because of this you authentication cookies are encrypted in two different ways.

Try setting the machineKey in your web.config. Here is tool that helps generating the machineKey http://aspnetresources.com/tools/machineKey

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top