【问题标题】:Mono MVC3 failed to map pathMono MVC3 无法映射路径
【发布时间】:2011-12-04 22:42:16
【问题描述】:

我正在尝试让 MVC3 应用程序在单声道下运行,并且在部署到我的服务器之前一切都很顺利...

我目前得到:

Failed to map path '/projects/_ViewStart.cshtml'

System.InvalidOperationException: Failed to map path '/projects/_ViewStart.cshtml'
  at System.Web.HttpRequest.MapPath (System.String virtualPath, System.String baseVirtualDir, Boolean allowCrossAppMapping) [0x00000] in <filename unknown>:0 
  at System.Web.HttpRequest.MapPath (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.Hosting.HostingEnvironment.MapPath (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.Hosting.DefaultVirtualPathProvider.FileExists (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.FileExistenceCache.FileExists (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.VirtualPathFactoryManager.PageExistsInVPP (System.String virtualPath, Boolean useCache) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.VirtualPathFactoryManager.PageExists (System.String virtualPath, Boolean useCache) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.WebPageExecutingBase.FileExists (System.String path, Boolean useCache) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.StartPage.GetStartPage (System.Web.WebPages.WebPageRenderingBase page, System.String fileName, IEnumerable`1 supportedExtensions) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.RazorView.RenderView (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer, System.Object instance) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19 () [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter (IResultFilter filter, System.Web.Mvc.ResultExecutingContext preContext, System.Func`1 continuation) [0x00000] in <filename unknown>:0 

错误。我可以确认所有文件和 DLL 都存在,但路径看起来不正确,肯定它应该在视图文件夹中查找确实存在的东西吗?

是否需要进行某种设置以确保它位于正确的视图位置?我还注意到文件路径之前没有“~”字符...

我浏览了网络并尝试了各种解决方案,但似乎没有一个有效..

【问题讨论】:

    标签: asp.net-mvc-3 mono fastcgi lighttpd


    【解决方案1】:

    看看你的 Apache 配置,对我来说是这样的

    运行失败 '/usr/bin/mod-mono-server2 --filename /tmp/mod_mono_server_bla --applications /testmono:/var/www/ModMonoMvc3Application --nonstop (null) (null) (null) (null) (空)(空)(空)'。原因:没有那个文件或目录

    因为我误解了配置选项AddMonoApplications。它应该是这样的:

    # "default" is defined in mods-available/mod_mono.conf
    AddMonoApplications default "/testmono:/var/www/ModMonoMvc3Application"
    
    <Location /testmono/>
        SetHandler mono
    </Location>
    

    我不小心写了“bla”而不是“default”,因为我以为它是应用程序名称,但实际上它定义了启动哪个服务器可执行文件。

    【讨论】:

      【解决方案2】:

      直接调用时遇到同样的错误

      HttpContext.Current.Server.MapPath("/")

      HttpContext.Current.Server.MapPath(Path.DirectorySeparatorChar.ToString()) 
      

      但这是可行的:

      HttpContext.Current.Server.MapPath("~")
      

      【讨论】:

        猜你喜欢
        • 2014-10-15
        • 1970-01-01
        • 2014-12-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-30
        • 2011-08-21
        相关资源
        最近更新 更多