ASP.NET MVC Layout errors on deployed web role

已答复 ASP.NET MVC Layout errors on deployed web role

  • jeudi 19 avril 2012 03:04
     
     

    I getting the following exception on an MVC 4 web application that I'm evaluating on Azure.

    Source: System.Web.WebPages
    Message: Section not defined: "main".
    Stack trace: at System.Web.WebPages.

    WebPageBase.RenderSection(String name, Boolean required) at ASP._Page_Views_Shared__Layout_cshtml.Execute() in e:\sitesroot\0\Views\Shared\_Layout.cshtml:line 77 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) at System.Web.WebPages.WebPageBase.PopContext() at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.b__22(IAsyncResult asyncResult) at System.Web.Mvc.Controller.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.b__3(IAsyncResult ar) at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.b__3(IAsyncResult ar) at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.b__4(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.b__3(IAsyncResult ar) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    I originally ported the app over to azure and deployed it over a month ago and it was working correctly back then.  I've done a fair bit of work on the app and have just redeployed to Azure and I'm seeing this error.  If I run the application either in the Azure emulator or as a standalone web app I have no issues and if I browse to a new page that didn't exist in the first deployment I also don't get an issue so it seems like something is being cached somewhere.

    I have completely deleted the role and redeployed and I have also browsed the App folder on the VM and confirmed that all of the cshtml files are current.  I have not configured the azure cache or CDN so I don't believe these are the cause.

    Does anyone have any ideas on where to look next?

    EDIT:

    I changed the section "Main" to be optional and I now receive the following error:

    The "RenderBody" method has not been called for layout page "~/Views/Shared/_Layout.
    cshtml".

    So it appears that it is actually some sort of nested layout issue.  Basically I have a single master layout _Layout.cshtml and a different sub layout for each section of the site.  The views then use the sub layout and each sublayout has @RenderBody() in it.  They all definitely work locally so there is something specific to the Azure web role.

    • Modifié MothSoln jeudi 19 avril 2012 05:44
    •  

Toutes les réponses

  • jeudi 19 avril 2012 07:23
    Modérateur
     
     

    Hi,

    It seems that the same problem from you:

    http://stackoverflow.com/questions/10220313/windows-azure-caching-cshtml-files

    Did ming's suggestion solve your problem?


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

  • jeudi 19 avril 2012 08:44
     
     

    No, that didn't help but I've done some more research and the issue appears to be with Html.RenderAction

    I'm wondering if this is a problem with MVC3 vs MVC4 on the Azure servers??  I have System.Web.Mvc as part of the bin folder but this is the only reason I can think of as to why it works locally and not on the Azure server.

    If I take my call to Html.RenderAction out the page loads without error.

  • jeudi 19 avril 2012 10:03
    Modérateur
     
      A du code

    Hi,

    I have tested it at my side, but unfortunately could not reproduce your problem, i have created a ActionResult in HomeController.cs, and add partial view for this action, and in index.cshtml page, use Html.RenderAction() to render this partial view. It's work fine both in local and cloud environment:

    ActionResult:

            public ActionResult Re()
            {
                ViewBag.Message = "custom";
                return PartialView();
            }

    Add some text in Re.cshtml page,

    Render Re partial view in Index.cshtml page:

    @{
        Html.RenderAction("Re"); 
    }

    You can debug it now.

    Hope this helps.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

  • jeudi 19 avril 2012 13:57
     
     Traitée

    OK, problem solved.  The issue was the partial view being returned from the RenderAction call was failing.  The issue was that the partial view used data from a SQL Azure database to populate a select list and the connection settings to the database were incorrect.

    Now I thought I had tested the SQL Azure connection when I ran the application locally as I put in the Azure connection string but obviously not.

    Unfortunately the error that was thrown lead us on a bit of a goose chase.

    • Marqué comme réponse MothSoln jeudi 19 avril 2012 13:57
    •