Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 搜索自定义局部视图路径时,文件不存在_Asp.net_Asp.net Mvc_Iis 8 - Fatal编程技术网

Asp.net 搜索自定义局部视图路径时,文件不存在

Asp.net 搜索自定义局部视图路径时,文件不存在,asp.net,asp.net-mvc,iis-8,Asp.net,Asp.net Mvc,Iis 8,我在我们的MVC应用程序上遇到了一个奇怪的问题。我们继承了RazorViewEngine来创建一个自定义视图引擎,以便于在视图的排列中使用自定义逻辑 我们有一个潜在视图路径列表: PartialViewLocationFormats = new[] { "~/Views/Partial/Shared/Base/$thing/{0}.$otherthing.cshtml", "~/Views/Partial/S

我在我们的MVC应用程序上遇到了一个奇怪的问题。我们继承了RazorViewEngine来创建一个自定义视图引擎,以便于在视图的排列中使用自定义逻辑

我们有一个潜在视图路径列表:

            PartialViewLocationFormats = new[]
        {
            "~/Views/Partial/Shared/Base/$thing/{0}.$otherthing.cshtml",
            "~/Views/Partial/Shared/Base/$thing/{0}.cshtml",
            "~/Views/Partial/Shared/Base/{0}.$otherthing.cshtml",
            "~/Views/Partial/Shared/Base/{0}.cshtml"
        };
然后重写FileExists方法,如:

        protected override bool FileExists(ControllerContext controllerContext, string virtualPath)
    {
        return base.FileExists(controllerContext, this.ParsePath(controllerContext, virtualPath));
    }
ParsePath方法如下所示:

        private string ParsePath(ControllerContext controllerContext, string virtualPath)
    {
        string newPath = virtualPath;
        BaseController controller = controllerContext.Controller as BaseController;
        if (controller != null)
        {
            if (controller.Model != null)
            {

                if (!string.IsNullOrEmpty(controller.Model.Thing))
                {
                    newPath = newPath.Replace("$thing", controller.Model.Thing);
                }

                if (!string.IsNullOrEmpty(controller.Model.OtherThing))
                {
                    newPath = newPath.Replace("$otherthing", controller.Model.OtherThing);
                }
            }
        }

        return newPath;
    }
这在本地运行良好,但在发布到Win 2012 IIS8 box后,我发现以下错误:

文件“/Views/Partial/Shared/Base/Footer.blar.cshtml”不存在

TargetSite: System.Web.Compilation.BuildResult GetVPathBuildResultInternal(System.Web.VirtualPath, Boolean, Boolean, Boolean, Boolean, Boolean)

StackTrace: at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) yadda yadda yadda
“/Views/Partial/Shared/Base/Footer.cshtml”确实存在,为什么会引发异常

我的直觉是代码很好,这是IIS的一个问题-我已经检查过网站是否运行集成模式等


有什么想法吗

这是因为当您将应用程序设置为debug=“false”时,MVC进行了优化。一旦我设置了debug=“true”,这个错误就消失了。

这是因为当您将应用程序设置为debug=“false”时,MVC进行了优化。一旦我设置debug=“true”,这个错误就消失了