ASP.NET MVC Webform Hybrid

We (me and my team) have an ASP.NET MVC application, and we integrate a page or two, which are web forms. We are trying to reuse the main page from our part of the MVC application in the part of WebForms. We found a way to render a partial view of MVC in web forms that works fine, before we try to postback, which is the reason for using WebForm.

Mistake:

Failed to verify viewstate MAC address. If this application is hosted on an Internet Farm or Cluster, make sure that the configuration settings are the same validation key and validation algorithm. AutoGenerate cannot be used in a cluster.

Code for rendering a partial view from WebForm (credited to "How to enable a partial view inside a web form") :

public static class WebFormMVCUtil
{
    public static void RenderPartial(string partialName, object model)
    {
        //get a wrapper for the legacy WebForm context
        var httpCtx = new HttpContextWrapper(System.Web.HttpContext.Current);

        //create a mock route that points to the empty controller
        var rt = new RouteData();
        rt.Values.Add("controller", "WebFormController");

        //create a controller context for the route and http context
        var ctx = new ControllerContext(
            new RequestContext(httpCtx, rt), new WebFormController());

        //find the partial view using the viewengine
        var view = ViewEngines.Engines.FindPartialView(ctx, partialName).View;

        //create a view context and assign the model
        var vctx = new ViewContext(ctx, view,
            new ViewDataDictionary { Model = model },
            new TempDataDictionary());

        //ERROR OCCURS ON THIS LINE
        view.Render(vctx, System.Web.HttpContext.Current.Response.Output);
    } 
}

My only experience with this error is in the context of a web farm, which is not the case. In addition, I understand that the machine key is used to decrypt ViewState.

Any information on how to diagnose this problem will be appreciated.

Work: For now, you need to move the contents of the header to PartialView, and then use the AJAX call to invoke the page using Partial View from WebForms, and then using PartialView directly in MVC Views. In addition, we can still share the non-technical parts of the main page, that is, everything that is not specific to MVC. However, this is not an ideal solution; a server solution is still necessary.

, solutino , , JavaScript, script, .

+3
3

. .

ViewUserControlWithoutViewState<T> ViewUserControl<T> .

+1

ViewState MVC .

0

MAC?

http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx

EnableViewStateMac = false

Safety note

This attribute should never be set to false on a production website.

since your site is an MVC site and the view state is not actually used.

0
source

All Articles