views:

347

answers:

3

Hi!

Im trying to setup a login functionallity in C#, where I have a form on default.aspx that posts to Login.aspx where the logic is runned.

But when the form posts to Login.aspx I get a MAC viewstate verification error. What is this and why?

When I call Login.aspx direct from the browser I get no error, only when the form posts itself to it.

Default.aspx form code:

    <form id="form1" runat="server" method="post" action="Login.aspx">
<div>
  <input type="text" name="lgn" id="lgn" runat="server" /> Login<br />
  <input type="password" name="pwd" id="pwd" runat="server" /> Password<br /><br />
  <input type="submit" name="submit" id="submit" value="Login" runat="server" />

</div>
</form>

Is there any restrictions to posting a form to another page in the same project, or is there anny setting i have missed?

Thanks in advance

I solved it by using the PostBackURL property on a asp:button instead of the action property on the form tagg, like so:

<asp:Button id="btnSubmit" runat="server" text="login" PostBackUrl="~/Login.aspx" />
+1  A: 

The usual way these forms work is posting back to themselves (and then maybe redirecting to another page).

Hans Kesting
A: 

This may happen if you have multiple webserver with load-balancing routers in front. I've written a blog post about that. Read it here. You basically have to add the machineKey setting to your web.config specifying a validation and decryption key. That will ensure it is the same on all machines. If none is specified, it will be autogenerated.

Juri
+2  A: 

I think you want to be using the the following

<asp:Button ID="btnClickie" Text="Click Me" runat="server" PostBackUrl="~/Login.aspx" />

instead of setting the action for the form to Login.aspx, but you'll have to pull the previous page's data. You can register the previous page with this...

<%@ PreviousPageType VirtualPath="~/Page1.aspx" %>

Then you'll be able to pull the controls from the other page (provided they have runat="server" on them). At least in theory.

http://aspalliance.com/135 has a fair article on ViewState, but it doesn't have a smoking gun for this problem.

OldTroll