I have two environments: Dev and QA. Both running Windows Server 2012 R2. I have an MVC 4 site set up as an application under an existing Classic ASP site. (The existing ASP site does not have its own Web.Config file.)
They're configured exactly the same in Dev and QA except for the machine name and IP addresses. They're both running the exact same build.
The HomeController.cs file is very simple:
public ActionResult Index()
{
return View();
}
The Index.cshtml file is just as simple:
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
/Views/_Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>
/Views/_ViewStart.cshtml:
@{
Layout = "~/Views/_Layout.cshtml";
}
On the Dev server, when I go to my site: http://dev/MySite/Home/Index/
It properly executes _ViewStart.cshtml and uses the default _Layout.cshtml that was defined:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h2>Index</h2>
</body>
</html>
On the QA server, when I go to my site: http://qa/MySite/Home/Index/
It just renders this:
<h2>Index</h2>
I compared the IIS configurations (even exported them as applications to review the settings in XML, they're the exact same save for the computer name). I edited _Layout.cshtml and _ViewStart.cshtml to throw exceptions, but they never get executed.
What makes things stranger is if I try to manually set the Layout in the view by setting Layout = "~/Views/Layout.cshtml";
on the QA server, I get the following error:
The layout page "~/Views/_Layout.cshtml" could not be found at the following path: "~/Views/_Layout.cshtml".
On Dev, I can manually set the layout this way and it works just fine.
If I do @Url.Content("~/Views/_Layout.cshtml")
on Dev and QA, I get the following output:
/MySite/Views/_Layout.cshtml
What could possibly be causing this? We have other MVC 4 sites running as applications on these servers under the same website and they run perfectly fine.
答案 0 :(得分:2)
The IT Department has the anonymous authentication of the site configured to use a specific user account and not the application pool identity. Unfortunately, the folder that new application was installed to didn't provide permissions for IIS_IUSRS on the QA environment.
This allowed the website to continue to halfway work and render views, but it couldn't execute _ViewStart.cshtml or find the layouts.