且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

布局网页" {}路径"无法找到

更新时间:2022-10-15 11:20:51

好像你可能有权限问题。随着你给的信息,好像不能够找到_Layout.cshtml文件的最可能的原因。

使用Server 2008和IIS 7,用于ACL的(名为IIS程序池{应用程序池名称}),以及这些标识的应用程序池的都有自己的身份是由该IIS_IUSRS组的一部分。此外,默认的Inetpub / wwwroot目录将已阅读了IIS_ISRS组的权限。所以,如果你没有得到你所需要的权限,我会认为应用程序池其实也不是用正确的身份运行。

原因之一的身份可能不正确是匿名身份验证用户身份的设置。进入该网站(或整个服务器)认证控制和编辑匿名身份验证规则的应用程序池标识运行。

这是一个有点猜测,但它似乎的这个家伙有几乎相同的问题。

布局网页" {}路径"无法找到

We just got a new Windows 2008 R2 server and I am trying to set up an MVC 3 site in IIS 7.5 with the Razor View Engine. I am getting a strange error when I access the default route.

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

This is strange because I explicitly set the Layout from within /views/home/index.cshtml like so:

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

I am 100% certain that the /views/shared/_layout.cshtml exists in the file system. Here's a screenshot.

If I remove the Layout = "~/Views/Shared/_Layout.cshtml"; from my view, the page will render out the contents of /home/index.cshtml all by itself (without any of the code from _Layout.cshtml). I have also tried setting the layout using _ViewStart.cshtml.

Anyone know why MVC wouldn't be able to "find" the layout file? This website works perfectly fine when running in the built-in web server for visual studio.

Here's my stack trace:

[HttpException (0x80004005): The layout page "~/Views/Shared/_Layout.cshtml" could not be found at the following path: "~/Views/Shared/_Layout.cshtml".]
   System.Web.WebPages.WebPageExecutingBase.NormalizeLayoutPagePath(String layoutPage) +204956
   System.Web.WebPages.WebPageBase.PopContext() +150
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +384
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +33
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +784900
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +784976
   System.Web.Mvc.Controller.ExecuteCore() +159
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371

It seems like you probably have a permissions issue. With the info you've given, it seems like the most likely cause of not being able to find the _Layout.cshtml file.

With Server 2008 and IIS 7, application pool's have their own identity used for ACL's (named IIS AppPool{App Pool Name}), and these identities are made part of the IIS_IUSRS group. Also, your default inetpub/wwwroot directory will have read permissions for the IIS_ISRS group. So, if your not getting the permissions you need, I would think that the App pool is not in fact running with the correct identity.

One reason the identity may be incorrect is the setting for Anonymous Authentication user identity. Go into the Authentication control for the site (or the whole server) and edit the Anonymous Authentication rule to run as the Application Pool Identity.

This is a bit of a guess, but it seemed this fellow had nearly the exact same issue.