Re: asp.net problem, viewstate mac

  • From: prateek aggarwal <prateekagarwal99@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Wed, 24 Nov 2010 13:09:42 +0530

Sameer,
Its absolutely true that the problem of viewState Mac is pretty common
amongst the programmers community, at least, the people I know or met.
For sure it does bottleneck your well written program, which seems
really frustrating at times.

I know what you are talking about, as there was instance, when I too
was somewhat in the similar state that you are in now.
for me too  the runtime error has occurred, and though I won’t go into
the technicalities of that why did it happen, here are some possible
solutions which I can suggest you from little of my experience in
programming with asp.net.

first, I tell you a fact, the problem occurs not because you have
written something erroneous, but it’s a bug with .net framework. May
be it will boost your confidence about your capabilities. Lol!

You can try one of the following things:
1.      when you are binding the grid, check with a simple condition that
if the page is  postback or not, don’t bind it until its postback.
2.      if that’s not possible in certain scenarios, try to place some
beautiful images on your pages, so that it takes some time in loading.
This way, when you have pressed a button and having the grid on the
page load,  the page will post back, probably before its loaded
completely. To my knowledge, that’s not a problem in usual scenarios,
unless you do some other crazy settings with your program.

3.      a few of my friends who had this problem and contacted me, one of
them has once said that he is in great hurry to get this worked, he
just do not have time for any experiment. I told him just a simple
thing to move the buttons or other controls which are required to be
post back to an another page.
So in your case, if you are in hurry, you can even try to move your
textbox and button to an another page, (may be a new page) and just
link it from your page where the grid is.  I know that’s not a
rational solution, but it works for people in hurry, because you can’t
tell this to your clients.

There are several more solutions/suggestions which could be tried, but
the above stated
ones should work in most of the situations.

Cheers!
Prateek agarwal.





On 11/24/10, Varun Khosla <varun.lists@xxxxxxxxx> wrote:
> Hi Sameer,
>
> Which runtime error do you get when you add the mentioned settings in
> web.config? Could you post that here?
>
> When I ran into this problem, I simply modified the following code in
> web.config:
>
> <pages>
> ...
>               </pages>
>
> as follows:
>
> <pages enableEventValidation="false" viewStateEncryptionMode="Never"
> enableViewStateMac="false">
> ...           
> </pages>
>
> Make sure you modify the existing <pages> section in web.config. Add
> this section only when you don't have already one. Anyway, if you post
> the runtime error you're getting after modifying the config file, that
> would help in understanding why this solution failed for you.
>
> HTH
>
> On 11/19/10, RicksPlace <ofbgmail@xxxxxxxxx> wrote:
>> Hi Sameer: I hope you figure it out and then post up the solution. I too
>> am
>> running asp.net 3.5 now. I have not encountered that type of problem in
>> years now but remember having to specify the machineKey and other
>> properties
>> in the config file when I moved the site to a production IP Host. Anyway,
>> let me know what you find out since learning is always a good thing to
>> share
>> and solutions passed along to later related descendant problems is what
>> e-lists like this are all about.
>> Rick USA
>> ----- Original Message -----
>> From: "sameer manohtra" <sameermanohtra@xxxxxxxxx>
>> To: <programmingblind@xxxxxxxxxxxxx>
>> Sent: Friday, November 19, 2010 7:10 AM
>> Subject: Re: asp.net problem, viewstate mac
>>
>>
>> thanks to those who have responded on the query.
>> i'm trying different things suggested in blog posts and else with no
>> success.
>>
>> as per the version, its .net version 3.5, that's vs2008.
>>
>> as i said, it works fine on my local host, and i'm sure that i'm not
>> running it on web farm.
>>
>> sameer!
>>
>>
>> On 11/19/10, RicksPlace <ofbgmail@xxxxxxxxx> wrote:
>>> By the way, are running asp 2.0 or which version, is your IP Host running
>>> the same and do you have the machineKey hard coded and it's related
>>> values
>>> specified in your config file if you are running on a web farm or other
>>> place where execution kmay be broken between postings?
>>> There can be several reasons for this type of message and it would be
>>> necessary to actually see the code, config file and perhaps get some info
>>> from your IP Host to resolve it without just trying suggested solutions
>>> and
>>> finding one that works for you, inefficient, slow but perhaps your best
>>> bet
>>> if you don't have access to an experienced pro in this arena. View State,
>>> encryption and all that jazz is one of the more complex issues needed to
>>> be
>>> delt with in Internet Programming and especially for processing split
>>> between processes on diferent machines of a Web Farm or other remote or
>>> multi-processing situation..
>>> Anyway, See if you have specified a machineKey and the related fields,
>>> properties, in the <system.web> section of your config file - at least I
>>> have used one for my Website that works fine with some rather complex
>>> nested
>>> controls and Master Pages. Make sure you don't have 2 <form> statements
>>> in
>>> your page, make sure you have it in the Details Page - this according to
>>> one
>>> of the other posts but I had no problem using it in either the Master nor
>>> the Detail Page... Hmmm, I can't think of anything else to look at but
>>> you
>>> should get some ideas from the prior blog I mentiioned and here. I had to
>>> specify a machineKey value when I moved my site up to a IP Host if I
>>> remember correctly but that was using VS 2005 and several years ago so I
>>> do
>>> not recall exactly what all it entailed other than that specification.
>>> Rick USA
>>>
>>> ----- Original Message -----
>>> From: "RicksPlace" <ofbgmail@xxxxxxxxx>
>>> To: <programmingblind@xxxxxxxxxxxxx>
>>> Sent: Friday, November 19, 2010 5:30 AM
>>> Subject: Re: asp.net problem, viewstate mac
>>>
>>>
>>>> Hi: Did you read the following group of Postings on this subject? It was
>>>> one of the first ones I found googling and has a little info about folks
>>>> having that or a similar problem and a response from a MS guy.
>>>> http://forums.asp.net/t/955145.aspx
>>>> Rick USA
>>>> ----- Original Message -----
>>>> From: "sameer manohtra" <sameermanohtra@xxxxxxxxx>
>>>> To: <programmingblind@xxxxxxxxxxxxx>
>>>> Sent: Friday, November 19, 2010 3:44 AM
>>>> Subject: Re: asp.net problem, viewstate mac
>>>>
>>>>
>>>> well, I read that this is one of the most common problems developer
>>>> faces specially while working with gridview controls where data is to
>>>> be sought from database.
>>>> Wondrously,  I couldn’t find anyone amongst the folks I know who has a
>>>> working solution of this nagging issue.
>>>> At most of the places, I’ve seen that doing enable viewstate mac
>>>> “false” fix the issue, but what am I doing wrong, I get runtime error
>>>> on the page everytime I implement this one line.
>>>>
>>>> I’m sure some of you guys must have come across of this problem, as
>>>> I’m aware that here we have so many experienced  developers.
>>>>
>>>> Please help me, its muddling  my head and I’m just out of solution.
>>>> Any help will be deeply appreciated and will prove of absolute utility.
>>>>
>>>> Sameer!
>>>>
>>>>
>>>>
>>>> On 11/19/10, Jacques Bosch <jfbosch@xxxxxxxxx> wrote:
>>>>> Perhaps you already read these pages, but anyway.
>>>>> http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx
>>>>> http://www.eukhost.com/forums/f15/fix-validation-viewstate-mac-failed-6085/
>>>>>
>>>>>
>>>>> On Thu, Nov 18, 2010 at 4:21 PM, sameer manohtra
>>>>> <sameermanohtra@xxxxxxxxx>wrote:
>>>>>
>>>>>> Hi guys,
>>>>>> I’ve trapped into a problem yet again:
>>>>>> I’m developing a website using asp.net and I have encountered a
>>>>>> problem where i’d like to know from you guys.
>>>>>>
>>>>>> I have developed  a page where there’s a gridview control that’s
>>>>>> showing data from the database, and a textbox  and   button that
>>>>>> stores the value in the database.
>>>>>> Its all working fine on my computer (LOCALHOST), but on live server it
>>>>>> seemed to have  messed up.
>>>>>>
>>>>>> Simply, when I try to place a text in textbox and click button for add
>>>>>> (which should store the data into database), I get this strange 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”.
>>>>>>
>>>>>>
>>>>>>
>>>>>> from some googling I found that this can be fixed by placing following
>>>>>> in web.config:
>>>>>> enableViewStateMac="false"
>>>>>> viewStateEncryptionMode="Never"
>>>>>> enableEventValidation="false"
>>>>>>
>>>>>>
>>>>>> unfortunately, when I’ve added this to my web.config, the page did not
>>>>>> load and started giving runtime error.
>>>>>>
>>>>>> I have even tried to place the same code in .aspx file, result of
>>>>>> which too was similar (RunTime Error).
>>>>>>
>>>>>> Does someone have any solution?
>>>>>>
>>>>>> Please, share it, I’m in high
>>>>>> Need to do the same.
>>>>>>
>>>>>> Any response will be appreciated.
>>>>>>
>>>>>> Sameer!
>>>>>> __________
>>>>>> View the list's information and change your settings at
>>>>>> //www.freelists.org/list/programmingblind
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Jacques Bosch
>>>>>
>>>> __________
>>>> View the list's information and change your settings at
>>>> //www.freelists.org/list/programmingblind
>>>>
>>>> __________
>>>> View the list's information and change your settings at
>>>> //www.freelists.org/list/programmingblind
>>>>
>>>
>>> __________
>>> View the list's information and change your settings at
>>> //www.freelists.org/list/programmingblind
>>>
>>>
>> __________
>> View the list's information and change your settings at
>> //www.freelists.org/list/programmingblind
>>
>> __________
>> View the list's information and change your settings at
>> //www.freelists.org/list/programmingblind
>>
>>
>
>
> --
> Varun
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: