MVC5网站找不到布局页面



我有一个MVC5网站在Windows 2008 R2服务器上的IIS下运行。网站运行了几个小时很好,然后我开始看到错误消息说

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

如果我重新启动不是最佳的网站,错误就会消失。你知道这里可能发生了什么吗?该网站确实使用异步控制器,这可能会导致线程无法访问文件时出现某种权限问题吗?

确保在~/Views/_ViewStart.cshtml文件中设置了正确的路径:

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

你似乎设置了这样的布局:

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

您需要将布局的位置指定为绝对路径:

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

最新更新