locked
Validation of viewstate MAC failed - Session Variables does not work properly!!! RRS feed

  • Question

  • User-425599523 posted

    Hello All

    Website is hosted in the hosted provider

     

    Out of <g class="gr_ gr_33 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="33" data-gr-id="33">sudden</g> we are getting this error

     Validation of <g class="gr_ gr_35 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="35" data-gr-id="35">viewstate</g> MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same <g class="gr_ gr_36 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="36" data-gr-id="36">validationKey</g> and validation algorithm. AutoGenerate cannot be used in a cluster.

     See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.

     


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3429.0

     

    We did the follow

     

    1. Added in the Webconfig

     <pages  enableEventValidation="false" viewStateEncryptionMode="Never">

     But still the same error

    2. Added in the EnableViewStateMac="false"   and True as well in the each asp.net pages

     But still the same error

     3. After adding this in the web.config

       <machineKey validationKey='6EBA439D3D866111346C4A00FF0C90D68CF93B93C970A6026AA58A57745D1EE360256C3ACAF5FD475CD1AA1FF63F713A9311B3A962041B4502A891DA47355F22'   decryptionKey='A00232E968FBD9E601226F6194C64C52383B8756C43BC5FC'   validation='SHA1'/>

     

    The error is gone<g class="gr_ gr_37 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace" id="37" data-gr-id="37">..</g> But session variables are not working properly<g class="gr_ gr_38 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace" id="38" data-gr-id="38">..</g> Sometimes it works, some it time <g class="gr_ gr_39 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace" id="39" data-gr-id="39">not..</g>We cant remove session variables

    Pls <g class="gr_ gr_108 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace" id="108" data-gr-id="108">Suggest..</g> Thanks

    Wednesday, September 4, 2019 1:00 PM

All replies

  • User753101303 posted

    Hi,

    It uses now a web  farm ? If yes and using "in process" session variables, you need a load balancer that takes care to forward requests from a given source always to the same server.

    AFAIK most balancers allows that (for example on Azure you can chose).

    If you have no choice then you'll likely have to change the session provider (for example a db or whatever) so that even if the user is directed to another server, it can still use the same session variables.

    Edit: BTW I try to use them as less as I can and if possible as a "browser session scoped cache" ie they are not accessed directly but exposed behind a strongly typed facade that loads them as needed. Avoid to load a session variable on one page and having another page to require this session variable being set from elsewhere. Avoid to store in a session variable a value that couldn't be reloaded if needed to first check if this is a load balancing problem.

    For now check the IIS log or use maybe https://docs.microsoft.com/en-us/dotnet/api/system.environment.machinename?view=netframework-4.8 and Session.SessionID to see if you stay on the same server and check you still uses the same session.

    Wednesday, September 4, 2019 2:30 PM
  • User-425599523 posted

    Thanks..

    I have verified there is no web farms or cluster.

    Any idea how to fix it?

    How to store session variables in Database (session provider) or any other alternatives.. pls let me know.. Thanks

    Friday, September 6, 2019 4:23 PM
  • User665608656 posted

    Hi bsarahim,

    Any idea how to fix it?

    To fix this issue, I suggest you can check your session state first, make sure if you have changed session state and provide us with information.

    Second, you can update the value of your machineKey to restore session.

    How to store session variables in Database (session provider) or any other alternatives

    For this question, you can follow these steps:

    1. Configure SQL Server for ASP.NET SQL Server session state first
    2.  Modify the Web.config file of the application

    For more step details, you could refer to this link :

    HOW TO: Configure SQL Server to Store ASP.NET Session State

    Best Regards,

    YongQing.

    Monday, September 9, 2019 8:20 AM