Last post Dec 01, 2008 07:10 AM by ironside14
Nov 26, 2008 04:50 PM|injvstice|LINK
I got a chance to upgrade to the Beta recently, and I run into a bit of an issue with my user controls.
I previously used RenderUserControl() and now I changed them to RenderPartial.
The problem I'm seeing is that (although I know -- it is evil) if something causes a postback with the control rendered on the page, I get an 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. "
In other words, to replicate the problem, I do this taking all my elements out of the process:
1. Create a test MVC application
2. Add a <asp:button> and link it to an empty OnClick handler on the server side.
If I load the page and click the button, i get the error mentioned above on Html.RenderPartial("LoginUserControl").
This is just for illustration purpose, we don't really have an asp:button on our page... unfortunately I need this type of behavior due to some controls that we have not yet migrated to MVC. We are working on fixing that issues, but in the meanwhile we need
to work as well as it did with RenderUserControl().
Nov 26, 2008 05:20 PM|hassan.live|LINK
ASP.NET MVC doesnt support postback. So you can not use a control that trigger a postback. If you need that kind of behavior; using those types of controll you should put them in a webform that is not a part of the mvc routing. You can use MVC and classic
ASP.NET web for side by side. For further studies how to use them read the article of scott hanselman:
Nov 26, 2008 05:51 PM|injvstice|LINK
Thank you, Hassan.
Supported or not, it seems odd that the issue is connected to rendering a user control. The postback works okay if there is no user control on the page. I would expect it to always break. Maybe I don't fully understand the interraction of the user control
with the page.
I will look into the routing and post an update after the holidays. Thank you for your answer.
Nov 26, 2008 08:26 PM|Augi|LINK
Hassan is right - ASP.NET MVC doesn't support ViewState and so postback is not supported too. If some component works successfully then it probably doesn't use ViewState.
Dec 01, 2008 07:10 AM|ironside14|LINK
As a workaround, you might consider turning off validation of the viewstate MAC for an individual page if you are sure you're validating everything safely yourself elsewhere.
(e.g. EnableViewStateMac="false" in your page directive)