1

I have a sample page called Redirect.aspx with following content;

<body onload="document.forms.container.submit()">
    <form id="container" runat="server" method="post" name="container">
        <input type="hidden" value="<%=Request["APP_ID"]%>" name="APP_ID" />
    </form>
</body>

the Page_Load method is following:

protected void Page_Load(object sender, EventArgs e)
{            
    container.Action = Configuration.Instance.PageToRedirect;
}

To this Redirect.aspx page, I'm directed from some external page. In the request context, I have APP_ID key, which is passed from this external page. Next, I want to pass this APP_ID value using POST to some other page, which is defined in the configuration. Unfortunately, I'm getting such error while redirecting:

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.

I don't want to disable view state validation (<pages enableViewStateMac="false">) because this is not the "solution" I want to apply.

Besides I don't understand why I'm getting such an error. Can someone get me through this ? Is there any other way to automatically submit a form on Page_Load event ?

Regards

jwaliszko
  • 16,942
  • 22
  • 92
  • 158

2 Answers2

1

2 ideas:

  1. Check if the value of <%=Request["APP_ID"]%> gets actually calculated and you are not posting that as a string. You can't post any html tag characters like "<" or ">". If the value doesn't get calculated it means you are not databinding the page. A quick solution would be putting this.DataBind() in your code behind file.

  2. Generate a MachineKey manually in your web.config (you can use an online tool to do that: http://aspnetresources.com/tools/machineKey). In one of my application it solved my problems even if I'm not in a web farm (now I don't remember the details of the problem though).

Also please clarify this: "Next, I want to pass this APP_ID value using POST to some other page, which is defined in the configuration" are you sure the error happens when you do the redirect as you state, or is it in this post? Are you trying to cross post a value to another application in a different domain? That is not possible normally.

Durden81
  • 966
  • 9
  • 25
  • Hello, 1. I'm not using html tag haracters in the POST string. Besides, the values are calculated. 2. I have generated the machineKey entry and pasted into web.config, but it didn't help. When it comes to clarification: I'm trying to POST data to application in the same domain: from http://localhost/app/Redirect.aspx to http://localhost/app/NewPage.aspx. The error occurs just after the javascript function document.forms.container.submit() is executed. – jwaliszko Jan 14 '11 at 19:02
  • Ok, I had to check those possibilities first. Also I have read that the form tag should not have any "action" attribute, I don't know now if ASP.net creates this attribute for you. – Durden81 Jan 14 '11 at 19:05
  • 1
    The funny thing is that if I include this enableViewStateMac="false" attribute into the <%@ Page ... /> tag, everything works. The action attribute seems to work properly then. The only thing is that such solution has security issues so I have to avoid that, and I don't know what is going on ;]. – jwaliszko Jan 14 '11 at 19:13
0

i think, you can edit your pages tag in web.config with:

<pages maxPageStateFieldLength="512">

maybe, it can fix your problem...

ogun
  • 1,314
  • 2
  • 16
  • 40