Question

I have 2 pages in sitefinity (w/MVC) that have different controllers with identical parameters. One returns a page with search results and all the form elements to conduct that search.

I would like a 'print' button on that first form to send all the form fields to a different page, with a different controller/component with the same parameters.

(I have posted the same question on Sitefinity's forums, but have not yet received a response. I have also been searching for this, but not finding similar results)

In ASP.Net, or Actual MVC, this would work easily.
In MVC I was able to do it like this:

            var d = document;
            var f = d.forms[0];
            window.open('', 'B2BDownload', 'width=900,height=800,resizable,scrollbars;');
            var pt = f.target;
            var pm = f.action;
            f.action = '/UtilityPages/DownloadInvoices';
            f.target = 'B2BDownload';
            f.submit();
            f.action = pm;
            f.target = pt;

but in Sitefinity's MVC that same code produces this error: (at the correct page)

Server Error in '/' Application.

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.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: 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.

Source Error: 


[No relevant source lines]

Source File: c:\Users\dsagmi\AppData\Local\Temp\Temporary ASP.NET Files\root\e2f026a5\8dd189ac\App_Web_15de2cba-1969-6a7f-bafc-ff00004b1c1a_20t98b8c6261_dealerportal_en.aspx.d63928b6.zmrfaltr.0.cs    Line: 0 

Stack Trace: 


[ViewStateException: Invalid viewstate. 
Client IP: ::1
Port: 41710
Referer: http://localhost:60876/history/order-invoice-history
Path: /UtilityPages/PrintInvoices
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36
ViewState: /wEPDwULLTE1NDc5NTk3MzZkZEkHl7CSK6SqsTcfmGWe//o1dcqh]

[HttpException (0x80004005): 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.]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +198
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) +432
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +8
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +40
System.Web.UI.HiddenFieldPageStatePersister.Load() +248
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +88
System.Web.UI.Page.LoadAllState() +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
System.Web.UI.Page.ProcessRequest() +72
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +58
    ASP.sfpageservice_15de2cba_1969_6a7f_bafc_ff00004b1c1a_20t98b8c6261_dealerportal_en_aspx.ProcessRequest(HttpContext context) in c:\Users\dsagmi\AppData\Local\Temp\Temporary ASP.NET Files\root\e2f026a5\8dd189ac\App_Web_15de2cba-1969-6a7f-bafc-ff00004b1c1a_20t98b8c6261_dealerportal_en.aspx.d63928b6.zmrfaltr.0.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET      Version:4.0.30319.18408
Was it helpful?

Solution

This occurs because the page contains view state, and view state is only decipherable by the page which generated it. The target page is trying to decipher this field, but it can't and is instead throwing an exception.

Immediately before the call to submit(), try searching the DOM for the hidden form field named "__VIEWSTATE" and set its value to the empty string (""). This will cause the destination page not to try to load view state.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top