Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
see the design code given below

ASP.NET
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="testpage.aspx.vb" Inherits="testpage" 
EnableViewStateMac="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
<title>Untitled Page</title>

<script type="text/javascript">

function callme(frmname)
{
var myForm = document.forms[frmname];
myForm.submit();
}

</script>

</head>
<body>
<form id="frm1" method="post" style='margin-top: 0px; margin-bottom: -10px'  runat="server"
action="Default.aspx">
<div id="button2" style="float: left;" önclick="callme('frm1');">
<a style="removed: pointer" class="smallfnt3">Register Now</a>
</div>

</form>
</body>
</html>


it shows error as

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.

Please Help.
Posted
Updated 16-May-12 2:29am
v2
Comments
ZurdoDev 16-May-12 8:39am    
When do you get the error? Just loading the page or posting back?
Mohamed Mitwalli 16-May-12 9:18am    
when did it happen ?
Rakesh S S 16-May-12 13:12pm    
the moment i click the div with id="button2"
it execute javascript and after that it shows the above error

This can be because of the 'action' attribute in your form tag. This error happen if you have specified an action on the forms element, and if the action is different than the page you are browsing to. Earlier, the action attribute was ignored. Remove the action attribute, or change it to post to the right page if you want to have viewstate enabled.

Details here: Validation of viewstate MAC failed after installing .NET 3.5 SP1[^]
 
Share this answer
 
Comments
Rakesh S S 16-May-12 12:51pm    
do i need to keep enable viewstate to false of this page
not getting your point
Sandeep Mewara 16-May-12 13:17pm    
Which part was confusing?

2 options - pick one of them
1. Remove 'action' attribute in your forms tag. Make it: <form id="frm1" method="post" style='margin-top: 0px; margin-bottom: -10px' runat="server"> (See any difference? There was an action attribute which I removed)
2. If you keep 'action' attribute, Add the redirect page where you are going to. Looks like it's not "default.aspx". add the next page where the execution is going.
Wendelius 16-May-12 15:47pm    
Good answer
Sandeep Mewara 16-May-12 15:53pm    
Thanks Mika.
Rakesh S S 17-May-12 1:03am    
i used master page
and form tag should be runat="server"
in order to place server control
and finally i need to use action attribute
work fine without runat server [form tag]
but not working with attribute runat
How to fix “Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster”


We were testing the deployment of a website onto 2 load balanced IIS 7 servers the other day, and the sites were loading fine. the next morning one of the testers was reporting an erorr on the website that said     ”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” . We looked at the error and realised that we need to create a static machinekey and add it into the web.config of both our IIS7 web servers to fix the issue.

Add following code in web.config.
C#
<machinekey validationkey="AutoGenerate,IsolateApps" decryptionkey="AutoGenerate,IsolateApps" validation="SHA1" decryption="Auto" />
 
Share this answer
 
if you remove your posted form runat server attribute it will work fine

<form id="frm1" method="post" style="margin-top: 0px; margin-bottom: -10px" runat="server">
action="Default.aspx"></form>


like this

<form id="frm1" method="post" style="margin-top: 0px; margin-bottom: -10px">
action="Default.aspx"></form>
 
Share this answer
 
Comments
Rakesh S S 16-May-12 12:49pm    
what if i got some server control inside form tag
i have make runat="server" in such scenario
Dain Ucak 16-May-12 13:09pm    
if you dont use master page make this.

<form id="form1" runat="server">
put your server side tags here
</form>
<form id="frm1" method="post" style="margin-top: 0px; margin-bottom: -10px">
action="Default.aspx">....
Rakesh S S 17-May-12 0:37am    
yes i am using master page
Dain Ucak 17-May-12 8:05am    
yes you can use master page. if you have a problem and took any advice about those problems, you need to develop some difference scenario.

for example. you are using master page and you have a server side form tag in this master page. you can close your form tag in your content page and reopen form tag which isnt server side.
look my example. i tried to tell you clearly.
firs this is my master page code between body tag

<body>
<div id="Container" style="width:100%; position:relative;" align="center">
<div style="width:1000px; height:300px;">
<form id="form1" runat="server">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">



<!--this form closing tag is contents form which wasnt server side -->
</form>
<%
if(Request.RawUrl.Contains("testA.aspx")){
%>
<!--This div is closing position absolute div which in content page for design your link in the page-->
</div>
<%} %>
</div>
</div>
</body>
now this is my testA.aspx which post to testB.aspx html codes
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</form>
<script type="text/javascript">

function callme(frmname) {
var myForm = document.forms[frmname];
myForm.submit();
}

</script>
<div style="position:absolute; top:50px; left:450px;">
<form id="frm1" method="post" style='margin-top: 0px; margin-bottom: -10px' action="TestB.aspx">
<div id="button2" style="float: left; cursor:pointer !important; cursor:hand !important;" önclick="callme('frm1')">aaa
</div>

and look at testB.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

i hope this will help you


Amin Mou 10-May-13 16:00pm    
tyyy :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900