I have created an ASP.NET-based relying party application and this application is deployed on farm-server where load balancing is enabled and sticky session is also used.

When request come from single server in that time its working fine but during the post back if request server is changed in that time it throws an exception "Key not valid for use in specified state".

I have tried to set same machine key on both server but still facing same problem.

I have found on net the alternative solution is set enableViewStateMac="false".

Can i use this, and what is demerit of this?


To answer your question, according to MSDN:

This attribute should never be set to false in a production Web site.

(Of course, the default is also false ...) Which suggests to me that you want to be very careful doing this.

Can you include a link to the resource you found online that suggested you switch this off?

Next, according to an MSDN blog:

The problem is that if a POST back is performed and goes to a different server, you will get a nice little error message saying “Corrupt View State“.

To fix this, you can either set enableViewStateMac to false in the element or specify a common value for the validationKey attribute in the element across all servers (in the farm).

Which suggests to me that, unless the error message has changed (quite possible), this isn't what you're running into.

Take a look at this accepted answer - https://stackoverflow.com/questions/686873/allowing-session-in-a-web-farm-is-stateserver-good-enough/687162#687162 - over on Stack Overflow to make sure you're setup correctly.

MSDN also has an article ASP.NET Session State Overview that discusses setting up session state.

At this point, I think it's a configuration issue. Changing machine.config should have restarted the app pools, so that's probably not the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.