0

I have a MVC5 website running under IIS on a Windows 2008 R2 server. The website works fine for a few hours and then I start seeing error messages saying

        The layout page "~/Views/Shared/Master.cshtml" 
could not be found at the following path:
    "~/Views/Shared/Master.cshtml".

The error goes away if I restart the website which is not optimal. Any idea on what may be going on here? The website does use async controllers and could that be causing some sort of permission issues where the thread does not have access to the file?

1 Answers1

1

Make sure that in your ~/Views/_ViewStart.cshtml file you have set the correct path:

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

You seem to have set the Layout like this:

@{ 
    ViewBag.Title = "title"; 
    Layout = "_Layout"; 
}

You need to specify the location to the layout as absolute path:

@{ 
    ViewBag.Title = "title"; 
    Layout = "~/Views/Shared/_Layout.cshtml";
} 
MRebai
  • 5,344
  • 3
  • 33
  • 52
  • I have the layout specified as an absolute path in all my view files. If I did not do that, my site would always give me the same error. In my case, it works fine for a few hours and then can no longer find the file. –  Sep 12 '14 at 13:25
  • It could be some server side code which is setting the layout (such as custom action filters, or the ViewResult overload which allows to specify a layout, ...). – MRebai Sep 12 '14 at 13:27
  • Your tip about the action filter was key. I had a redirect in a custom action filter that when removed solved the problem. –  Sep 12 '14 at 18:29