Validation of viewstate MAC failed

Discussion in 'ASP .Net' started by George Thompson, Nov 1, 2007.

  1. Hi,

    I come from an ASP background, and I am currently working on a .NET
    project, so please excuse me if this is a dumb question ...

    I have written a dynamically generated menu that uses the following
    structure (looping through for each menu item needing to be
    displayed):

    <tr>
    <td class='menuclass' onmouseout='menu(this)'
    onmouseover='menu_over(this)'>My Menu Text</td>
    </tr>

    the result is that the td, whose class contains a bg image, has a
    simple mouse over image change. Now what I would like to do is have
    it so that if you click anywhere on the td, it fires an onclick event
    like this:

    onclick="aspnetForm.action='mynewpagetogoto.aspx';
    aspnetForm.submit();"

    This works fine in an asp environment, however when I click on a td
    with that onclick event in an asp.net environment I get this error:

    Validation of viewstate MAC failed. If this application is hosted by a
    Web Farm or cluster, ensure that <machineKey> configuration specifies
    the same validationKey and validation algorithm. AutoGenerate cannot
    be used in a cluster.

    as a result I am being forced to set an href link around the text
    instead ... although this works, it would be ideal to have the entire
    td clickable because the image change that happens does suggest that
    it is and may be confusing for visitors.

    Also, more importantly, I would like to understand the source of this
    error, as it does surprise me that I cannot navigate away from this
    page in this fashion.

    Any help would be greatly appreciated!

    Thanks!
    George Thompson, Nov 1, 2007
    #1
    1. Advertising

  2. Keep in mind, you aren't navigating away from the page, you are trying to
    post to another page. That will cause problems. The ASP background really
    hurts a lot of ASP.Net developers. First, you don't need to post to another
    page. Instead, you can have it call a client-side script that performs it's
    own postback to the page you are on, no reason to go to another page.
    ASP.Net was designed so you can encapsulate all the logic within a single
    page, no need to chain together a whole bunch of pages to do the same job.
    You can do things like show steps in a process using a wizard control or a
    series of panels, no needing to create a page for each step.

    In this case, if you're showing information on a page and want to click on
    something to show more, you can use panels. Put your table with images and
    onclick events in one panel, then when you do a postback, hide the first
    panel, load the information into the second panel.

    You're running into a problem with something known as ViewState. ViewState
    keeps information regarding the state of all the controls on a page. The
    code you're using will get the ASP.Net page to attempt to post it's data to
    another page. ASP.Net doesn't like that approach because the ViewState is
    encrypted to avoid it being tampered with. The second page knows that the
    ViewState it was sent isn't valid as it can't decrypt it so it throws an
    error.

    You could pass all the form fields that you need to submit to the second
    page through a querystring during your onclick by changing the browser
    location instead of submitting the form. that would let you send the data
    without running into a viewstate issue as you would no longer be submitting
    the form.

    The biggest trick is to forget what you knew of ASP, ASP.Net is an entirely
    new beast and is truly an event-driven model even though it shares a name
    with classic ASP. It's the biggest trip-up for developers making the
    transition is applying ASP knowledge to ASP.Net. Start looking at how simiar
    tasks are handled and you'll get a much better feel of the platform and how
    to avoid these types of issues.

    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - Expression


    "George Thompson" <> wrote in message
    news:...
    > Hi,
    >
    > I come from an ASP background, and I am currently working on a .NET
    > project, so please excuse me if this is a dumb question ...
    >
    > I have written a dynamically generated menu that uses the following
    > structure (looping through for each menu item needing to be
    > displayed):
    >
    > <tr>
    > <td class='menuclass' onmouseout='menu(this)'
    > onmouseover='menu_over(this)'>My Menu Text</td>
    > </tr>
    >
    > the result is that the td, whose class contains a bg image, has a
    > simple mouse over image change. Now what I would like to do is have
    > it so that if you click anywhere on the td, it fires an onclick event
    > like this:
    >
    > onclick="aspnetForm.action='mynewpagetogoto.aspx';
    > aspnetForm.submit();"
    >
    > This works fine in an asp environment, however when I click on a td
    > with that onclick event in an asp.net environment I get this error:
    >
    > Validation of viewstate MAC failed. If this application is hosted by a
    > Web Farm or cluster, ensure that <machineKey> configuration specifies
    > the same validationKey and validation algorithm. AutoGenerate cannot
    > be used in a cluster.
    >
    > as a result I am being forced to set an href link around the text
    > instead ... although this works, it would be ideal to have the entire
    > td clickable because the image change that happens does suggest that
    > it is and may be confusing for visitors.
    >
    > Also, more importantly, I would like to understand the source of this
    > error, as it does surprise me that I cannot navigate away from this
    > page in this fashion.
    >
    > Any help would be greatly appreciated!
    >
    > Thanks!
    >
    Mark Fitzpatrick, Nov 1, 2007
    #2
    1. Advertising

  3. "George Thompson" <> wrote in message
    news:...

    > I come from an ASP background


    > Any help would be greatly appreciated!


    I can only reiterate what Mark has said.

    ASP.NET is totally different from ASP in almost every way. The biggest
    mistake that people coming from an ASP Classic background make is to imagine
    that ASP.NET is the next version of ASP and, even worse, that VB.NET is the
    next version of VBScript... In fact, there's a school of thought which says
    that a good reason for choosing C# over VB.NET is precisely because you
    won't bring any of the VBScript baggage with you. I'm assuming that you're
    fairly familiar with JavaScript, so you won't find the C# syntax too
    daunting...

    I would strongly advise you to get a copy of this:
    http://www.amazon.com/ASP-NET-All-R...4073238?ie=UTF8&s=books&qid=1193931423&sr=8-2
    and work your way through it, otherwise you'll find ASP.NET a very steep
    uphill struggle.

    However, I can assure you that once you have grasped the basics, you'll
    never want to go back to ASP Classic... :)


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Nov 1, 2007
    #3
  4. try this search, it will give you results that should help a lot:
    http://www.google.com/search?q=enableViewStateMAC
    -- Peter
    // Abandon all hope, ye who enter here.
    http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    BlogMetaFinder: http://www.blogmetafinder.com



    "George Thompson" wrote:

    > Hi,
    >
    > I come from an ASP background, and I am currently working on a .NET
    > project, so please excuse me if this is a dumb question ...
    >
    > I have written a dynamically generated menu that uses the following
    > structure (looping through for each menu item needing to be
    > displayed):
    >
    > <tr>
    > <td class='menuclass' onmouseout='menu(this)'
    > onmouseover='menu_over(this)'>My Menu Text</td>
    > </tr>
    >
    > the result is that the td, whose class contains a bg image, has a
    > simple mouse over image change. Now what I would like to do is have
    > it so that if you click anywhere on the td, it fires an onclick event
    > like this:
    >
    > onclick="aspnetForm.action='mynewpagetogoto.aspx';
    > aspnetForm.submit();"
    >
    > This works fine in an asp environment, however when I click on a td
    > with that onclick event in an asp.net environment I get this error:
    >
    > Validation of viewstate MAC failed. If this application is hosted by a
    > Web Farm or cluster, ensure that <machineKey> configuration specifies
    > the same validationKey and validation algorithm. AutoGenerate cannot
    > be used in a cluster.
    >
    > as a result I am being forced to set an href link around the text
    > instead ... although this works, it would be ideal to have the entire
    > td clickable because the image change that happens does suggest that
    > it is and may be confusing for visitors.
    >
    > Also, more importantly, I would like to understand the source of this
    > error, as it does surprise me that I cannot navigate away from this
    > page in this fashion.
    >
    > Any help would be greatly appreciated!
    >
    > Thanks!
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Nov 1, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray Stevens

    Validation of viewstate MAC failed

    Ray Stevens, Aug 4, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    814
    Brock Allen
    Aug 9, 2005
  2. Not Me

    Validation of viewstate MAC failed

    Not Me, Dec 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    476
    Not Me
    Dec 8, 2005
  3. Sergej Grickov

    Error: Validation of viewstate MAC failed

    Sergej Grickov, Jan 27, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    11,675
    Teemu Keiski
    Feb 4, 2006
  4. aaaaaa
    Replies:
    1
    Views:
    438
    Alvin Bruney - ASP.NET MVP
    Mar 23, 2006
  5. sck10
    Replies:
    6
    Views:
    913
    sck10
    Sep 1, 2006
Loading...

Share This Page